I have a number of strings that have a format loosely like this:
String blah = "Blah bleh bluh Id. 24 bleh" ;
String bleh = "Foo Bar Foo Id 24" ;
String foo = "Blah Foo Bleh Bar Tag.93 foo" ;
String bar ="Junk Jibberish Id.93" ;
Where I have some text, ultimately followed by some string that is in a set of possible identifiers (ID, Id, Identifier, Tag, etc.), followed then by either no spacing, a period and a space, just a period, or just a space, and then some number (1-4 digits) and possibly more text after that
I want to capture the substring in the format of “id93” or “tag93” or “id24” etc.
Kind of a specific question, I know, but I have no consistent single characters to separate the data I’m trying to capture.
What Regex pattern should I follow?
Use regex pattern
\b(id|tag)\.?\s*(\d{1,4})\bwith case insensitivity modifier and join groups 1 & 2.Edit: Java regex format:
\\b(id|tag)\\.?\\s*(\\d{1,4})\\b