Help me to create regex to only get numbers

Hi All ,
need ur help to only extract data using the regex with some use cases as below:

**Use case **
LOREM LS8515, WEN+ FEED, WATER (E570)
LOREM IPSUM 8515
LOREM IPSUM-8515
LOREM IPSUM8515
LOREM IPSUM8515 WATER2570

OUPUT NEEDED : 8515

Guys please note Lorem Ipsum can be any words or symbol thank you

Thank you guys

1 Like

@StevenIsRobotOnline

(?<=LOREM IPSUM\s*-*)\d{4}

Hi @StevenIsRobotOnline

(?<=LOREM LS|LOREM IPSUM-|LOREM IPSUM|LOREM IPSUM )\d+

Hi @StevenIsRobotOnline

Matches= System.Text.RegularExpressions.Regex.Matches(yourstringinput,"((?<=[A-Z]+\s+[A-Z]+\s*\-?)\d+)")

Datatype of Matches is IEnumerable(System.Text.RegularExpressions.Match)

Hope it helps!!

Hi @StevenIsRobotOnline

You can use the regular expression to get the required output 8515

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=\w+\s+)\d{4})”)

image

Hope it helps!!

hi @StevenIsRobotOnline

can you try this

system.text.regularexpression.regex.match(“\d{4}”).value

Hello @StevenIsRobotOnline ,
You can try this:
(?<=LOREM IPSUM\s*-*)\d+
I hope this Helps you.
Regards;)

Guys please note Lorem Ipsum can be any words or symbol thank you

Guys please note Lorem Ipsum can be any words or symbol thank you

@StevenIsRobotOnline

you try mine it works for any context!!

Hi @StevenIsRobotOnline

Matches= System.Text.RegularExpressions.Regex.Matches(yourstringinput,"((?<=[A-Z]+\s+[A-Z]+\s*\-?)\d+)")

Datatype of Matches is IEnumerable(System.Text.RegularExpressions.Match)

Hope it helps!!

@StevenIsRobotOnline Try with this one :
(?<=.\s-*)\d{4}

@StevenIsRobotOnline

Hi @StevenIsRobotOnline

You can use the following code to get the desired output:

[A-Za-z ]*(\d{4})(,|[a-zA-Z]+|\s)

Hope it helps! :smiley:

Hey,
Try With This Pattern:(?<!(WATER))\d{4}
image

System.Text.RegularExpressions.Regex.Match(str_,“\d{3,}”)

Hope it will help you!!

Hi @StevenIsRobotOnline

Check the below expression

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=(^[A-Z]+\s+[A-Z]+)|([A-Z]+\s+[A-Z]+)|[A-Z]+\s+[A-Z]+\s+|[A-Z]+\s+[A-Z]+\-)\d{4})”)

hi im not really familiar with regex ,

so how do i get the output caused when i use it on my script it shows
System.Text.RegularExpressions.MatchCollection

i only need : 8515 in a string as an output

@StevenIsRobotOnline

Str_output=System.Text.RegularExpressions.Regex.Match(INputString,“8[0-9]+”).Value

Okay @StevenIsRobotOnline

=> Assign -> StrOutput = System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“((?<=(^[A-Z]+\s+[A-Z]+)|([A-Z]+\s+[A-Z]+)|[A-Z]+\s+[A-Z]+\s+|[A-Z]+\s+[A-Z]+\-)\d{4})”).Value

Store the Input data in a String variable and in above expression pass the variable in the place of yourStringinput place.
The StrOutput is also a String Variable.

Hope you understand!!

Hi Its working now but still not perfect
image

it still have missing value

the use case is this
1.WILDUN DUMA 8515 → 8515
2. WILAN DC1218 → 1218
3. WILAN DC0818H ->0818
4.WILEN DC1218H ->1218
5. WIILENUN EN997, RSPO MB, GEM+ FOOD, FEED (E436) ->997

THANK YOU