简体   繁体   中英

Regular expression - Find and Replace in Dreamweaver

I have over a thousand webpages I need to grap html data within a certain field and then not replace that data but I need to copy that data to a meta field above in head of same html document.

I found code below somewhat use full.

find:

<span class="CatStyle">(.*)</span>

replace eg.

<span class="CatStyle">$1</span> <meta name="Category" content="$1">

But How would I use / could I use regular expression to find said data above but then instead of replacing like i have in above example, could I replace / insert the var $1 into <meta name="Category" content="$1"> within head of document, instead of inserting underneath of span. ?

Any Ideas?

NOTE : To manipulate HTML, you can use better tools - HTML parsers - than an S&R dialog with regex support.

For a one-off job , if you need to use the pattern inside a search and replace dialog and there is only one meta tag with the name equal to Category before the span , you may use

(<meta name="Category" content=")[^"]*(">[\s\S]*<span class="CatStyle">)([\s\S]*?)(</span>)

and replace with $1$3$2$3$4 backreference sequence.

Details :

  • (<meta name="Category" content=") - Group 1 capturing <meta name="Category" content=" string
  • [^"]* - 0+ chars other than "
  • (">[\\s\\S]*<span class="CatStyle">) - Group 2 capturing "> , then any 0+ chars (as many as possible) up to the last <span class="CatStyle"> and then <span class="CatStyle"> itself
  • ([\\s\\S]*?) - Group 3 capturing any 0+ chars, as few as possible, up to the first...
  • (</span>) - Group 4 capturing </span>

The $n are backreferences to the groups defined in the pattern with the help of paired (...) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM