0

I do want to match all subbstrings which are between {{ and }}

When this substring does not contain . , the regex works fine :

"When he come, {{person}} will give his son {{something}}".match(/{{(\w*)}}/g) ; 

Result :

["{{person}}", "{{something}}"]

Now , if this substring contains .(dot) , the regex does not work as it is expected :

"When he come, {{person.firstname}} will give his son {{something}}".match(/{{(\w*)}}/g) ;

Result :

["{{something}}"]

How to change the regex to be able to mach also substrings contains DOT , for example here : person.firstname . ?

2 Answers 2

3

or use this pattern to match anything between {{ and }}

{{([^}]*)}}

explanation:

[^}] a character class, anything but "}"
Sign up to request clarification or add additional context in comments.

Comments

1

\w will only match a-z, A-Z, 0-9, _, cf. http://www.w3schools.com/jsref/jsref_regexp_wordchar.asp.

Use this regular expression to include an arbitrary number of points as well:

/{{([\w\.]*)}}/g

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.