Extract string

andrea93

Member
Hi I have to analyze a text and if there is an error code I have to extract it. The code is variable but is always of length 8 and is alphanumeric. (Es.DGHE2008) Regex?
 

sahil_raina_91

Active Member
I tried the regex on Regex101.com, and it is working.
Please share your screenshots from Blue Prism which will help us understand more.
 

Attachments

  • Regex.png
    50.1 KB · Views: 24

sahil_raina_91

Active Member
A space can be matched with \s.
[A-Za-z0-9\s]{8}

Example:
(Es.DGHE2008) gives "DGHE2008"
(Es.DGHE200 ABC) gives "DGHE200 "

If I understood it wrong, please provide the text and what you want to extract from it.
 

andrea93

Member
A space can be matched with \s.
[A-Za-z0-9\s]{8}

Example:
(Es.DGHE2008) gives "DGHE2008"
(Es.DGHE200 ABC) gives "DGHE200 "

If I understood it wrong, please provide the text and what you want to extract from it.
This regex extract also string only text ( for example ABCDEFGH) but it have to exctract only text with char and number
 

sahil_raina_91

Active Member
Please answer these questions:
1) Will the text always be enclosed in ()? Example : (ABCEDFGH)
2) Will the text always contain char AND Number's?
3) How many numbers, minimum AND maximum, can exists? Example (ABCD1234) has 4 numbers, (ABC12345) has 5 numbers. So minimum of 4 maximum of 5.
 
Last edited:

andrea93

Member
1) no, i used () to explain a example
2) yes
3) it's variable, the lenght it's constaint

Probably text always start with DFHA
 
Last edited:

sahil_raina_91

Active Member
You will have to put a logic to decide if you want to extract regex, since regex will always extract values.

Here's what you can do :
Check if the text contains at least 1 number : If yes -> Use regex to extract the text of 8 characters. If no -> don't use regex since no numbers are present.

To identify if the text contains Numbers, you can use separate Regex : \d+
 

sahil_raina_91

Active Member
You can also try this regex : (?=.*[\d])(?=.*[A-Za-z])([a-zA-Z\d]{8})($|\s$) , but please test this with all possible variations
The above regex will extract :
SADFFF34 (along with space at end) from $#@$234@#$asdffDGHESADFFF34
 
Top