Text Format

absak

Member
Hello,

I had a condition to check in a Flow: number must be in the following format [1-2][0-9]{2}(0[1-9]|1[0-2]|20|3[0-9]|4[0-2]|[5-9][0-9])(0[1- 9]|[1-9][0-9]|2A|2B)([0]{2}[1-9]|0[1-9][0-9]|[1-9][0-9]{2})([0]{2}[1-9]|0[1- 9][0-9]|[1-9][0-9]{2})|([1-2][9]{12})

does regex do the job?
 

sivagelli

Well-Known Member
I am not sure how much value I am adding here with this comment but, here is the breakdown of the above regex

  • [1-2][0-9]{2} - Starts with either 1 or 2. Followed by 2 numbers in range 0-9
  • (0[1-9]|1[0-2]|20|3[0-9]|4[0-2]|[5-9][0-9]) - Starts with 0 followed by a number between 1-9 OR starts with 1 followed by a number between 0-2 OR 20 OR 3 followed by a number between 0-9 OR 4 followed by a number between 0-2 OR a number between 5-9 followed by a number between 0-9
  • (0[1- 9]|[1-9][0-9]|2A|2B) Starts with 0 followed by a number between 1-9 OR a number between 1-9 and 0-9 OR 2A OR 2B
  • ([0]{2}[1-9]|0[1-9][0-9]|[1-9][0-9]{2}) Two 0s followed by a number btween 1-9 OR a 0 followed by a number beween 1-9 aand 0-9 OR a number between 1-9 followed by 2 numbes between 0-9
  • ([0]{2}[1-9]|0[1- 9][0-9]|[1-9][0-9]{2})|([1-2][9]{12}) Two 0s followed by a number btween 1-9 OR a 0 followed by a number beween 1-9 aand 0-9 OR a number between 1-9 followed by 2 numbes between 0-9 OR a number either 1 or 2 followed by twelve times 9
It is really hard to thro some examples as well which might satisfy the format as the combinations are huge in number here.

The regex is valid one though!
 
Last edited:

absak

Member
I had used the test regex match but there is the following error:

Internal : Could not execute code stage because exception thrown by code stage: parsing "[1-2][0-9]{2}(0[1-9]|1[0-2]|20|3[0-9]|4[0-2]|[5-9][0-9])(0[1- 9]|[1-9][0-9]|2A|2B)([0]{2}[1-9]|0[1-9][0-9]|[1-9][0-9]{2})([0]{2}[1-9]|0[1- 9][0-9]|[1-9][0-9]{2})|([1-2][9]{12})" - [x-y] range in reverse order.
 

sivagelli

Well-Known Member
There is a space before '-' between one of the [..], that is causing parse exception.

Try this-

"[1-2][0-9]{2}(0[1-9]|1[0-2]|20|3[0-9]|4[0-2]|[5-9][0-9])(0[1-9]|[1-9][0-9]|2A|2B])([0]{2}[1-9]|0[1-9][0-9]|[1-9][0-9]{2})([0]{2}[1-9]|0[1-9][0-9]|[1-9][0-9]{2})|([1-2][9]{12})"
 
Last edited:

absak

Member
it works perfectly,

Now i had another request :), i had to replace in a given word: all caracter that are different from: Letter, spaces or "-" "_"; by " " (space)
 

sivagelli

Well-Known Member
Alright! I am assuming you would need to replace all the non-alphanumerics with space in a string. Here is the code-

Place the below code in the Global code options tab; also, add System.Text.RegularExpressions to Namespace

C#:
public string replaceNonAlphaWithSpace(string text)
{
         return Regex.Replace(text, @"([\W \-])", @" ");
}


For the Code stage, have an input parameter and an output parameter of text type. And in the code, make a call to the function 'replaceNonAlphaWithSpace' passing the input parameter.

Output = replaceNonAlphaWithSpace(Input)

Example:
Input: "Jos\e&f+"
Output: "Jos e f "

Post back how it goes!
 

absak

Member
now i'm testing a value of a date it should be "ddmmyyyy"
i used the following regex: "[0-9]{1,2}[0-9]{1,2}[0-9]{4}"

but for example if i put U9122019 text regex Match gives true
 
Top