22-02-2017...">

Delete part of a line between two different characters

This is my line = data-dateformat="dd-MMM-YYYY" class="info th-header-bc-ascolor">22-02-2017

Note that dd-MMM-YYYY can be any date format.

I want to remove every thing between data-dateformat="dd-MMM-YYYY" and >

This is my best attempt, but I know that it does not work.

mystring.substring(mystring.indexOf('data-dateformat="*"'), htmlcontent.indexOf('>'));

How can i solve this?

+7
javascript jquery
source share
1 answer

delete everything between data-dateformat = "dd-MMM-YYYY" and

You can try the following approach with String.prototype.replace () function and a special regular expression pattern:

 var str = 'data-dateformat="dd-MMM-YYYY" class="info th-header-bc-ascolor">22-02-2017', new_str = str.replace(/(data-dateformat="[^"]+")[^>]+>/, '$1>'); console.log(new_str); 

[^"]+ - will match any character except the value " , i.e. data-dateformat (between double quotes)

[^>]+ - will match any character except >

$1 - indicates the first captured group, which (data-dateformat="[^"]+")

+5
source share

All Articles