![]() |
|
#1
|
|||
|
|||
|
I'm trying to create PHP trim() function equivalent using pure JS code that truncates spaces from the begging and from the end of the given string. One of the solutions is to use two "while" loops that will run through the chars from the beginning and then on the end and cut spaces. Instead I want to write a RegExp to accomplish this. Here is the sample to give you an idea of my problem:
<font face="Courier New"> var str = new String(" and; n4m ") var patternTrim = /(^\s+)(.*)(\s+$)/; var arr = str.match(patternTrim); </font id="Courier New"> Note the space char in the middle of the evaluated string. The resulting string i want to have looks like this "and; n4m" "I have not failed. I've just found 10,000 ways that won't work." (Thomas Edison) |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|