Regular Expression

matuopm

Member
I have an issue with a regular expression. I have an application that has several textfields. But in one of these fields there is a string which contains a number in the following format.

Code:
2561546
125.456/7
K2561546
KV2561546
k256.154/6
kv256.154/6
kV256.154/6
Kv256.154/6
KV2.123.132/6

 2561546
 125.456/7
 K2561546 
 KV2561546 
 k256.154/6   
 kv256.154/6   
 kV256.154/6   
 Kv256.154/6   
 KV2.123.132/6



K2561546

The String can have one of the upper formats.
KV can be there or not. It can be lower or uppercase mixed. Then KV is followed by a number that can be between 5 and 8 digits long.
between the numbers can be dots and dashes. Before and after the string there can be spaces.

I can't get a regular expression to select all the possible variations.
So far I have:
^(K|k|\d)(V|v|\d)(\d|\.|\/){1,11}$

It captures each string of upper Block but fails to catches string that start with spaces or end with spaces
 

Attachments

  • regex101.png
    138.9 KB · Views: 17

gil.silva

Active Member
Hello,

Please, check this pattern does what you need: [KkVv]*[\d./]{5,11}

I'm not sure of the context, if you are extracting a text with multiline our everything is a single line.
But, if you have one text field per line, so you can use: ^\s*[KkVv]*[\d./]{5,11}\s*$

Let me know if you need any clarification.
 

Attachments

  • Regex.png
    84.8 KB · Views: 8
Top