How to write the regex to get the words before dot from 456yti.computer.com

Ankitha2
Tera Contributor

I have given an example expression above in the question but i want to get the characters before the dot for any expression. 

4 REPLIES 4

Richard Hine
Tera Guru
Tera Guru

Ankitha,

You want something like /^([a-z0-9]*)\./ suggest you try this on somewhere like regex101.com.

Hope this helps,

Richard

Hi Richard, thanks for the ans. I have tested in regex101. com in the above example I should the characters till the dot but now I am getting the dot also

Rahul Priyadars
Giga Sage
Giga Sage

try this

/[^.]*/

Tested the result- String before first occurrence of character . here Its Dot.

find_real_file.png

Another one

find_real_file.png

Regards

RP

Abhijit4
Mega Sage

Hi,

Your requirement can be achieved by using JavaScript split() method as well instead of using regex pattern as shown below.

var testText="firsttext.middletext.lasttext";
var array=test.split(".");
gs.print(array[0]);

if requirement can be achieved with Javascript methods then I would prefer Javascript methods over regex pattern.

I am adding this answer just in case someone finds it useful in future.

Thanks and Regards

Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP