Parenthesis brackets and the word "The" from a string

I am trying to compute the regular expression myself and to no avail if I can get the last bracket to disappear from the string.

For instance:

[The day the earth stopped]

I can only get:

The day the Earth stopped]

with the following RegEx code:

/(\[|\](^The ))\2/

I strive simply:

The day the earth stopped

Any help would be greatly appreciated. I spent 3 hours trying to figure it out on my own ... That I give up .: 3

+3
source share
2 answers

You can try:

\[The\s(.*)]

If you need to do this to cut out the brackets, even if β€œThe” is not, you can try:

(?:\[The\s|\[)(.*)]

, , "the" "The" , :

(?:\[[Tt]he\s|\[)(.*)]

"The" :

var title = new Array();
title[0] = "[The Day the Earth Stood Still]";
title[1] = "[Independence Day]";
title[2] = "[the Day the Earth Stood Still]";

alert(title[0].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);
alert(title[1].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);
alert(title[2].match(/(?:\[[Tt]he\s|\[)(.*)]/)[1]);

: http://jsfiddle.net/aSwYz/

+2

, , , ,

(?<=\[The\s*)[\w\s]*(?=\])

0

Source: https://habr.com/ru/post/1772140/


All Articles