Buca Bay - Always nice

Dua tiko noqu toa loaloa, na yacana ko… laga mai…

JavaScript Regex match all characters

June19

JavaScript regular expressions (browser) do not have a modifier allowing the dot (.) to match all characters including the newline like the ’s’ modifier does for PERL and PCRE in PHP.

However a cool tip I learnt just recently is that using a character class and it’s negated version will allow you to match all characters. Eg: /[\s\S]/g will match all characters in a JavaScript Regular Expression.

I used this trick in the ASCII to Hex conversion JavaScript code I posted a few days ago and thought to mention it.

Related posts:

  1. ASCII to Hex in JavaScript This JavaScript will add a method to the String object, that converts the ASCII string to a hex string consisting...
  2. Base conversion in JavaScript I just realized recently that you can convert between number bases in JavaScript using the built in method Object.prototype.toString() and...
posted under javascript, regex

Email will not be published

Website example

Your Comment:

 
Tag Cloud