Welcome Guest

Pages: 1
Regular Expressions
hoeniPostApril 30, 2014, 10:46
Newbie
Posts: 19
Registered:
April 30, 2014, 07:38
Normal topicRegular Expressions

Hi,

I would really love to be able to use regular expressions to do search and replace on a variable or tag.

Best regards,

Tobi

2MR2PostApril 30, 2014, 13:02
Avatar photo
Administrator
Posts: 2079
Registered:
August 23, 2012, 19:27
Normal topicRe: Regular Expressions

I'll put a 'RegExp Find and Replace' action function on the list. The Apple API for regular expressions is not available for Snow Leopard so the function may be a noop for that OS.

angangPostApril 30, 2014, 13:24
Beginner
Posts: 25
Registered:
August 23, 2013, 03:38
Normal topicRe: Regular Expressions

Good thing ! Thanks

hoeniPostApril 30, 2014, 14:45
Newbie
Posts: 19
Registered:
April 30, 2014, 07:38
Normal topicRe: Regular Expressions

Wow, great! Thanks! (I'm not interested in SL anyway 😉 )

hoeniPostMay 1, 2014, 04:47
Newbie
Posts: 19
Registered:
April 30, 2014, 07:38
Normal topicRe: Regular Expressions

Now that I slept over it :-), there would be two useful ways to use them:

    Replace a text by another text: s/^(\S+) - (\S+)$/\2: \1/i in a field
    Extract to Yate variables: /^(\S+) - (\S+)$/i ==> Variable1, Variable2
2MR2PostMay 1, 2014, 08:48
Avatar photo
Administrator
Posts: 2079
Registered:
August 23, 2012, 19:27
Normal topicRe: Regular Expressions

There are numerous issues with the extract due largely to the fact that Yate action functions do not comprise a full programming language. However, since the Apple regular expression implementation is based on the extremely powerful ICU implementation, I think the replace can be used to do pretty much everything. The ICU specification can be found at:

http://userguide.icu-project.org/strings/regexp

The replacement text is templated so that you can extract all or individual capture groups. Using this technique you could construct a 'new string' with components delimited so that you could use the other Yate text based functions to extract individual matched components. So as an example if your pattern had two capture groups you could have a replace template of:

"<endleft>$1<endmiddle>$2<endright>"

This would give you access you to:
everything before the first capture group
the first capture group
everything between the two groups
etc.

While not as aesthetic for those rarer times you want to extract, it will work and does not require the use of incremental variables. If you use a common delimiter you could even use a Repeat With function to iterate between the components.

The function as is now planned will support options (outside the pattern) for Match All, Match First, Match Last, Case Insensitive. Further, both the pattern and replace template will perform a pre-scan for \v constructs doing the appropriate properly escaped replacements prior to the matching process.

mikesPostDecember 29, 2014, 15:01
Newbie
Posts: 9
Registered:
November 7, 2014, 15:19
Normal topicRe: Regular Expressions

Has this made it into Yate yet and I just cannot find it?

My use case: In titles for classical music it is common to include the piece or work, then the actual track title. For example:
English Ste No. 1 in A major, BWV 806: I. Prelude
English Ste No. 1 in A major, BWV 806: II. Allemande
English Ste No. 1 in A major, BWV 806: IIIa. Courante I

What I am trying to do is create an action that will help me replace the pattern:
in [A-G].*,
with:
,

or something like the code:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@" in [A-G].*," options:0 error:&error];
NSString *result = [regex stringByReplacingMatchesInString:searchText options:0 range:NSMakeRange(0, [searchText length]) withTemplate:@","];

Any timeline on something of this kind of functionality?

2MR2PostDecember 29, 2014, 15:15
Avatar photo
Administrator
Posts: 2079
Registered:
August 23, 2012, 19:27
Normal topicRe: Regular Expressions

Unless you're on Snow Leopard you can use the Regular Expression Replace function. 🙂

mikesPostDecember 29, 2014, 20:17
Newbie
Posts: 9
Registered:
November 7, 2014, 15:19
Normal topicRe: Regular Expressions

Sweet! Such an amazing product! Thank you!

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.04 seconds.