- 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 02:51 AM
@Amit Pandey- Out of interest, why did you not point to my earlier response which provides the Regex and the solution rather than just repeat the same?
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 03:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 02:56 AM
Hi @Amit Pandey @Robbie ,
I want to get the value as below and not separating the alphanumeric
123Abc12CD
Instead of aphanumeric it contains numerical then the regex should give the numerical value.
Then the regex should give the 5005123 value. String passed will be dynamically so the regex should give the alphanumeric or numeric based on the string
var str = "this is a test 5005123";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 03:03 AM
Hi @kali,
Use the below regex to extract the numeric characters from the String
var str = "this is a test 5005123";
var rgr = /(\d+)/g;
var data =str.match(rgr);
gs.print(data);
Result: 5005123
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 01:26 AM - edited 08-01-2024 01:28 AM
Hi @kali
(So my response is not lost in the thread)
Use the below code to separate the alphanumeric characters into separate strings:
var str = "this is a test 123Abc12CD";
var rgr = /([A-z]+)|(\d+)/g;
var data =str.match(rgr);
gs.print(data);
Result: this,is,a,test,123,Abc,12,CD
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie