Regex starts with and replace words within a string
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
I'm parsing a long list of degree programme names which don't have consistency in the key words: Man, Manag, Manage, Management, etc. I need to convert all of these words in each string to the full "Management". The same applies to other words but I'm assuming that I need to run separate passes on these other words to repeat the process.
Trouble is that the words to change can be anywhere within the string including the end: "BSc Manag", "BSc Int Manage Full Time", "BSc Bus Man".
The regex I've worked out (and using in the RegEx node) - \b([mM]an\w) - successfully identifies the start of each word and then looks for the 'begins with' pattern. However, I'm struggling to get it to work on the end of a string as there's no subsequent characters - ie "BSc Bus Man" isn't matched as there's no char after "Man". Using \W does solve this but it then doesn't work with where there is a following character, ie "Manag"! I also can't reduce the 'begins with' pattern to [mM]a as this would also pick up 'Marketing' which I don't want...
Any ideas! I'm sure I'm missing something obvious!
Also - which is better for the 'find and replace' operation - REGEX functions in the 'Formula' node (possibly in an IF THEN ELSE statement) or stick with the 'Regex' node?
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@spettifor One way of doing this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks binuacs!
After sleeping on it I've realised that I'd just missed the greedy quantifier (*) at the end: \b([mM]an\w*) now picks up all variants including 'Man'! This regex string should be easily adaptable and should work as a reasonable 'starts with' expression.
