- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2024 06:39 AM
Hi All,
I am using regex to get a aphanumeric or numer from a string . I am using regex
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2024 11:25 PM
var str1 = "this is a test r11MS0AB8";
var str2 = "this is a test 123Abc12CD";
var str3 = "this is a test 51571008";
var regex = /\b(?=[a-zA-Z0-9]*\d)[a-zA-Z0-9]+\b/;
var match1 = str1.match(regex);
var match2 = str2.match(regex);
var match3 = str3.match(regex);
gs.print(match1 ? match1[0] : 'No match'); // Output: r11MS0AB8
gs.print(match2 ? match2[0] : 'No match'); // Output: 123Abc12CD
gs.print(match3 ? match3[0] : 'No match'); // Output: 51571008
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2024 09:31 PM
Hi @kali
Here you go-
var str1 = "this is a test 5005123";
var str2 = "this is a test 123Abc12CD";
var regex = /(\d+[A-Za-z]*\d*[A-Za-z]*)/;
var match1 = str1.match(regex);
var match2 = str2.match(regex);
var value1 = match1 ? match1[0] : null;
var value2 = match2 ? match2[0] : null;
gs.info(value1); // Output: 5005123
gs.info(value2); // Output: 123Abc12CD
Please mark my answer helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2024 11:18 PM
Hi @Amit,
Thanks for your response , There is a change in the ask I would like to get a regex to capture a word from the string if it has only digits/digits+letters/letters+digits/. Is it possible
For example
var str1= "this is a test r11MS0AB8; // output is r11MS0AB8
var str 2 = ""this is a test 123Abc12CD"; // output is 123Abc12CD
var str3 = "this is a test 51571008"; // output is 51571008
Is it possible to create a regex to show the above output. Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2024 11:25 PM
var str1 = "this is a test r11MS0AB8";
var str2 = "this is a test 123Abc12CD";
var str3 = "this is a test 51571008";
var regex = /\b(?=[a-zA-Z0-9]*\d)[a-zA-Z0-9]+\b/;
var match1 = str1.match(regex);
var match2 = str2.match(regex);
var match3 = str3.match(regex);
gs.print(match1 ? match1[0] : 'No match'); // Output: r11MS0AB8
gs.print(match2 ? match2[0] : 'No match'); // Output: 123Abc12CD
gs.print(match3 ? match3[0] : 'No match'); // Output: 51571008
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 01:25 AM
Hi @Amit Pandey ,
can you please let me know which website or resource you used to create this regex