English 中文(简体)
Dreamweaver regular expression substitution followed by number
原标题:

I m using Dreamweaver to update copyright dates across my site. I want to preserve the existing spacing (or lack thereof) between years. Examples: © 2002-2008 should update to © 2002-2009 © 2003 - 2008 should update to © 2003 - 2009 This is the regular expression I m using to accomplish this in Dreamweaver s find & replace function Find: ©s*(d{4}s*-s*)d{3}[^9]

Replace: © $1 2009

Here s the PROBLEM: This expression works, but has that that extra space between the hyphen and 2009. If I write the replace expression without the space, as © $12009 then dreamweaver looks for the 12,009th substitution in the find expression, and, not finding one, prints $12009.

问题回答

If you do not capture the - as well as the whitespace before or after it and only capture the leading year, then it ll make life a bit easier: ©s*(d{4})s*-s*d{3}[^9] then replace with: @ $1 - 2009

Just tried locally and it worked in the following test cases:

© 2002- 2008
© 2002-2005
© 2002- 2006

I do not have Dreamweaver, but I suppose that its regex engine doesn t support lookaround - at least this introduction from Adobe doesn t mention it. So you ll need a workaround. One thing you could do (not pretty, but it works):

Use © $1QQQQ2009 as your replacement string, and then do a second pass, searching for QQQQ and replacing that with nothing. As long as you re sure that you don t have any real occurences of QQQQ in your text somewhere :)





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签