Using REGEX to extract string after keyword
- 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
Hello..
I am trying to extract a string after 2 different variation of keywords. However the digits to be extracted can vary.
Any help or suggestions to do this will be very helpful and very much appreciated.
Sample data :
Value |
PROG P523205 (22009442) OFFSET WAS UTILIZED BY |
PROGRAM P1483107(22009933) FEE OFFSET PARTIALLY |
PROGRAM P1341224 (22009904) OFFSET FULLY UTILIZED |
PROG P1735249 OFFSET FULLY UTILIZED |
Expected Results
Value | Program |
PROG P523205 (22009442) OFFSET WAS UTILIZED BY | P523205 |
PROGRAM P1483107(22009933) FEE OFFSET PARTIALLY | P1483107 |
PROGRAM P1341224 (22009904) OFFSET FULLY UTILIZED | P1341224 |
PROG P1735249 OFFSET FULLY UTILIZED | P1735249 |
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Please try this formula with this regex configuration
regex formula : (?:PROG|PROGRAM)\s([A-Z0-9]+)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks!!
Can I confirm my understanding of the formula?
(?:PROG|PROGRAM) <- this is the conditional pick-up identifier? if I have a 3rd condition, say "PROD" could I use PROG|PROGRAM|PROD?
\s([A-Z0-9]+)<-- A-Z means that any alphabet character + up to 9 numerical will be picked up? If the string was "Program P1341224 2209904 inv ref" would it also end up picking the digit "2" as the 9th numeric?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @SArielle
One way of doing this even if you have PRG/PROGRAM/PROD etc.
(P\d+)
Many thanks
Shanker V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
oh so basically the formula can picks up as long as it has that alphabet and numeric behind?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @SArielle
Yes exactly.
However as I saw in your examples shared, the word was P, hence I have used the Regex to find P and all the digits following that.
Many thanks
Shanker V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If I used \d+ would it impact if let's say my program has a mixture of alphabets for example P124569A?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @SArielle
Using \d+ will help to read only the digits.
If you program is mixture of alphabets and digits. Then use the below Regex.
(P\d+\u{0,1})
Many thanks
Shanker V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hope this helps.
By using the regular expression pattern ([A-Z]\d+), you can extract the code that starts with any uppercase letter followed by one or more digits.
By using the regular expression pattern ([A-Z]\d+\u{0,1}) you can extract the code that starts with any uppercase letter followed by one or more digits followed by alphabet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you everyone. This is very helpful and very thankful for the supportive community here.
