I'm fetching some text-data from a TextArea in my app's UI. The eventual goal is to recognize a pre-determined format/pattern of text form this TextArea's entire data. (I'll be further using such filtered out text, if any, to further process the Employee IDs from such text)
The valid patterns are:
- EMP {and any valid ID here}. For e.g. EMP 1234
- A URL with this fixed pattern: http://emps/{id} For e.g. http://emps/1234
I'll be searching for such pattern text from the source data.
Here's a bunch of regex pattern and related logic I've developed so far:
string sourceText = "This will contain a bunch of text. Might also contain EMP 1234 and there could be a bunch of text after this pattern. There could again be EMP 4567 or http://emps/2345 We'll be extracting all such patterns. 3 in this case."
const string regexPattern =
"(\\bEMP(s|(id)|:|#)?\\s*?(id|#)?\\s*?(:|#)?\\s{1})(?<EMPid>(\\d{1,11}))(\\s*?(,|(and))\\s*?(?<EMPidnew>(\\d{1,11})))*";
var search = new Regex(regexPattern , RegexOptions.IgnoreCase);
MatchCollection matches = searcher.Matches(sourceText );
foreach (Match match in matches)
{
//If we reach this point it means that the sourceText contained text which matched our pattern
// From this point I'll be extracting the ID and process it further
}
The REGEX is not case-sensitive, which is intended. The REGEX which I've developed so far, by taking syntax references from some websites, correctly handles my first pattern i.e. of:
- EMP {and any valid ID here}. For e.g. EMP 1234
But now I'm not sure how I can modify my existing Regex pattern or add upon to the existing to proceed further for my second requirement i.e.
A URL with this fixed pattern:
- http://emps/{id} For e.g. http://emps/1234

