i’ve been working on a process that performs a data entry function after i’ve extracted certain key information from a string of data given in a statement.
So far, i’ve been able to get some success by breaking down my string manipulation into a few steps i.e. first splitting the string by spaces, then searching for the keyword that i need from the array and further split them up before i validate the information i need using regex statements. However, it seems like there’s a more efficient way of doing this by splitting and validating the information at the same time using regex statements.
A sample of the type of string i receive would be:
And the only information that i need starts from “LBC” and “T17FC0060B PTE 01”. Although instructions have been given to users to enter this in a format of LBC-<9/10 alphanumeric characters>-PTE-01 but as the source comes from a vendor, we have no control over how these information gets entered.
Thanks to the help of other users in this forum, i’ve been able to validate after splitting such entries with the following regex statement: System.Text.RegularExpressions.Regex.IsMatch(strData,“^\w{9,10}-?PTE-?0\d$”).
However, by first splitting this string by spaces, i would have failed to validate entries that were entered using the format given in the sample above. Therefore, would then be possible to split the chunk of string according to “^\w{9,10}-?PTE-?0\d$” instead?
Both statement works however, the correct format that users are supposed to enter is along the lines of “LBCT17FC0060B-PTE-01” where LBC is connected to the first character and PTE and 01 are both separated by hyphens.
As this input i purely determined by our external users we have no control over what they key in. So i would like to cater to as many variations as i possibly can. Is there a way to amend this regex statement to cater for different variations like missing hypens, extra spaces etc.?
One way that i’ve worked out was to first remove hyphens and spaces then run and edited regex statement like: