0

I have some html code that I need to regex and remove a part of it.

In this particular example I need to remove 2-columns.. The full string is name="2-columns.Heading-1" but needs to read name="Heading-1"

I would like this to be extendable because another example could be name="3-columns.Heading-1". So I want to remove everything after the starting point of name=" and the ending . (I also want to remove the .)

Can anyone help me form the correct regex? I'm struggling.

2
  • You do know that the name attribute is only valid for <form> and form elements, right? Commented Oct 15, 2014 at 14:16
  • @Terry Yes, this is actually for a particular CMS. I said it's html but really it's a handlebar template I'm parsing to replace with this particular CMS's proprietary tags. Commented Oct 15, 2014 at 14:18

3 Answers 3

1
[^"]*\.

Try this.Replace by empty string.See demo.

http://regex101.com/r/dZ1vT6/24

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

1 Comment

This worked great. I just had to add the global and multiline tags at the end for to go through the rest of the document. /[^"]*\./gm Thanks so much!
0

One way;

str = str.replace(/(^name=\")(.*\.)/, "$1");

Comments

0

Replace at group 1:

/name="(([^.]+)\.)Heading-1"/

Or:

'<tag name="2-columns.Heading-1">lalalala</tag>'.replace(/name="(([^.]+)\.)Heading-1"/, 'name="Heading-1"')

is:

"<tag name="Heading-1">lalalala</tag>"

and:

'<tag name="2-columns.Heading-2">lalalala</tag>'.replace(/name="(([^.]+)\.)Heading-1"/, 'name="Heading-2"')

is:

"<tag name="2-columns.Heading-2">lalalala</tag>"

or:

'<tag name="2-columns.Heading-1">lalalala</tag>'.replace(/(name=")(([^.]+)\.)(?=Heading-1")/, "$1");

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.