Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
HTML Pages with CSS and JavaScript
JavaScript match method
John La
Greenhorn
Posts: 16
1
posted 9 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is my problem:
console.log(" $".match("/^/s{4}\$/"));
This produces "null!". I thought the
string
backslash might need to be doubled, so I tried this:
console.log(" $".match("/^/s{4}\\$/"));
"null" also. Clearly, there's something I'm missing (my alopecia is acting up).
Thanks in advance.
Bear Bibeault
Sheriff
Posts: 67752
173
I like...
posted 9 months ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Two things:
1. When using regular expressions, it's best to use RE literals versus strings when you can. That way you get syntax checking, and avoid string escaping woes.
2. \s
So:
" $".match(/^\s{4}\$/)
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
John La
Greenhorn
Posts: 16
1
posted 9 months ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yours works, but I need the string version of the regular expression, which is causing me grief.
Bear Bibeault
Sheriff
Posts: 67752
173
I like...
posted 9 months ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
" $".match("^\\s{4}\\$")
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
urgent help--- fileformatting
Simple list table
Handling apostrophe in a Attribute Equals Selector
problem using thread pool in servlet, answering to a client page
More...