1

Originally I had a text like this;

asa#fathernode
{oi#string
oi2#string}

My script get an array like this (because other treatments are happening):

[ "asa#fathernode" , "{oi#string" , "oi2#string}" ]

I then make a string like this:

"asa#fathernode\n{oi#string\noi2#string}\n"

My script before I was getting the string untreated(without the "\n"):

asa#fathernode{oi#stringoi2#string}

and I was using:

textoFather = textoFather.match(/{(.*?)}/)[1];

to get what's between the curly braces, that was

"oi#stringoi2#string"

but I need it formatted as it was originally

oi#string
oi2#string

and because (I believe) that pattern isn't getting the "\n", the textoFather is returning null

I really need to get the "\n" for the rest of the script to keep working (Many other things are happening but the important is to get the text formatted), also the text presented is just an example, the actual text is HUGE and have some little differences (in the text string can actually be many other words not just string)

Obs:I really hope this is just a pattern(match) problem, but if it isn't I'm just a beginner in JavaScript and my native language isn't English so I would need a pretty detailed explanation on how to resolve my problem.

1
  • Formatting the question is already a big step to get good answers, so why don't you take the time to do that ? Commented Jun 24, 2013 at 8:22

1 Answer 1

4

because (I believe) that pattern isn't getting the "\n", the textoFather is returning null

You are right, the . meta-character does not match line breaks. From the MDN documentation:

(The decimal point) matches any single character except the newline character.

You can use [\s\S] instead:

/{([\s\S]*?)}/

[\s\S] is a character class. \s matches any white space character and \S matches every character that is not a white space character. So together, they match every character.

Or you could use [^}] which matches every character that is not }:

/{([^}]*)}/

Then you wouldn't even have to make the quantifier lazy.

Sign up to request clarification or add additional context in comments.

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.