I want to have a regex expression for excluding spaces and new line.

Taaha M
Tera Contributor

I want to have a regex expression which will include all characters but not new line and spaces.

2 REPLIES 2

Abbas_5
Tera Sage
Tera Sage

Hello @Taaha M,

Please refer to the link below:
https://www.servicenow.com/community/itsm-forum/need-a-regex-to-allow-all-characters-and-spaces-but-...

 

If it is helpful, please mark it as helpful and accept the correct solution, In future by refer to this solution it will helpful to them.

Thanks & Regards,

Abbas Shaik

debendudas
Mega Sage

Hi @Taaha M ,

You can use this regex: /[\s\n]+/g

 

Here is an example of this regex to modify a sentence which has spaces and new line:

var sentence = "This is a sentence with spaces and \n New lines";
var modifiedSentence = sentence.replace(/[\s\n]+/g, "");

gs.log(modifiedSentence);

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍