Regex

kali
Tera Contributor

Hi All,

I am using regex to get a alphanumeric value from a string . The regex i  used is [A-Za-z0-9] . Please help me on this .

Thanks in advance.

15 REPLIES 15

Simon Christens
Kilo Sage

Hi 

try this

var reg = /[a-zA-Z]*\d+[a-zA-Z]*/g; //Checks for both text and digits in the beginning
var subject ="This is a sample case for wefWF123AZBzxc";
var text = subject.match(reg);

gs.info(text[0]);

Hi @Simon Christens ,

var subject = "This is a sample case for A1BCDD2F(2000-07-03)";

the regex should return only A1BCDD2F . Please suggest a different regex and thanks in advance.

Hi again kali

Try this regex instead then

 

var reg = /[a-zA-Z0-9]*\d+[a-zA-Z]/g;

 

So

 

var reg = /[a-zA-Z0-9]*\d+[a-zA-Z]/g; //Checks for both text and digits in the beginning
var subject ="This is a sample case for A1BCDD2F(2000-07-03)";
var text = subject.match(reg);

gs.info(text[0]);

 

This returns

 

03/07/2024 12:39:55 (147) A1BCDD2F

 

Hi @Simon Christens,

Thnaks for your response , sorry  i could not reply back the regex should find alphabumeric value from the string and get digits value from the string.

var subject = "This is a sample case for A1BCDD2F(2000-07-03)";

var subject = "This is a sample case for 89076523";

The regex should get value from both A1BCDD2F and 89076523; Kindly help me on this 

 

Hi again,

Well then i dont know which scenarios you are looking for really but you can try this:

var reg = /[a-zA-Z0-9]*\d+[a-zA-Z]|\d+$/g; //Checks for both text and digits in the beginning

This also checks and gets x digits at the end of the

var reg = /[a-zA-Z0-9]*\d+[a-zA-Z]|\d+$/g; //Checks for both text and digits in the beginning
var subject ="This is a sample case for 89076523";
var text = subject.match(reg);

gs.info(text[0]);
08/08/2024 12:31:47 (771) 89076523