dutchclimber Posted April 29, 2009 Report Share Posted April 29, 2009 Situation 1: {AppName} = "TeamViewer (EN)" Situation 2: {AppName} = "Team Viewer (DE)" Situation 3: {AppName} = "TeamViewer" Situation 4: {AppName} = "Team Viewer" Now I would like to use {appname:regexreplace: :} To ged rid of the trailing " (xx)" with the result "TeamViewer" (as in 1 or 3) or "Team Viewer" (as in 2 or 4). I was hoping a {appname:regexreplace:(.*)(\s\(.*\)):$1} would suffice but that only works for 1 and 2 Any suggestions? R Link to comment Share on other sites More sharing options...
FranciscoR Posted April 29, 2009 Report Share Posted April 29, 2009 (edited) Regex function is your friend. That's the way to go, yep. {appname:regex:(.*)(\s\(\w+\))?:1} Edited April 29, 2009 by FranciscoR Link to comment Share on other sites More sharing options...
dutchclimber Posted April 29, 2009 Author Report Share Posted April 29, 2009 Regex function is your friend. That's the way to go, yep. {appname:regex:(.*)(\s\(\w+\))?:1} Just so I understand.... (.*) grabs (just about) anything in a 'greedy' fashion; parenthesis make it available as $1 \s is 'space \( is ( \w+ is one or more word characters \) is ) last 4 are within () so available as $2 ? Makes the preceding item $2 optional. Greedy, so the optional item is included in the match if possible. doesn't the first (.*) grab everything and ignore the rest? i tested this in Expresso and it seems to produce IN OUT TeamViewer (EN) TeamViewer (EN) Team Viewer (DE) Team Viewer (DE) TeamViewer TeamViewer Team Viewer Team Viewer So I just get what I started with. In that case a (.*) would have sufficed I suppose ;-) Sorry for turning this forum into a regex newbie school but it's just so damn promising once I get it.... Thanks for the patience. R Link to comment Share on other sites More sharing options...
FranciscoR Posted April 29, 2009 Report Share Posted April 29, 2009 (edited) I know this is confusing in the beggining. But you seem to be doing well. =) 1. Regexreplace is for replaces w/regex. What you are trying to do is to capture a 'matchgroup', hence you have to use regex function. And the code for 'matchgroup' #1 is '1', not '$1' (regexreplace). 2. \w+ stands for any alphanumeric character, greedy, yeah. It will stop on'\)'. Number of ways to do it. 3. If you test partial matches in Expresso, '(.*)' will match everything, yep. But if you have 2 matchgroups in Ketarin, {appname:regex:(.*)(\s.*):1}, you will capture only the first matchgroup. Better way to understand how this works is to do a couple of tests. ------------------------ Edit: I see what you mean, sorry. Use instead (\w+[\s]?\w+)(\s\(\w+\))? Edited April 29, 2009 by FranciscoR Link to comment Share on other sites More sharing options...
dutchclimber Posted April 30, 2009 Author Report Share Posted April 30, 2009 1: bunch of chars, maybe one or more whitespaces followed by a bunch of chars 2: whitespace, a '(', bunch of chars, ')' and all this on a 'maybe' basis I get it ! Thanks! R Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now