I have phone numbers on my file and I would like to surround each of them with braces, so if I have this:
"+49-1111"
"+49-2222"
I would like to run a replace operation and to get this:
["+49-1111"]
["+49-2222"]
Is that possible with the current vs code find/replace action?
If it is a dup sorry but I could find any explanation anywhere.
Thanks
This is more relevant to regular expression.
Find ("\+\d{2}-\d{4}"), replace the occurrences with [$1]
Be sure to turn the "Use Regular Expression" switch on.
Related
I'm getting a syntax error and invalid quantifier error in dreamweaver when I try to use a regexp in the source code.
The purpose is to find spaces in front of numbers on table cells and delete them.
(?<=>)\s+(?=\d)
this expression works on notepad++ but not in dreamweaver.
Can this be a Dreamweaver bug or the syntax is wrong?
Of course I can make a text search looking for >\s and replace by > but then I cant catch more spaces than the ones specified in the search string
thanks in advance
PS: Would be nice also to have a multisearch option in the dreamweaver search screen, to run multiple search and replace in one operation, like code clean up. An extension maybe?
I don't use DW but, since I have read several posts about lookarounds problems with DW, I assume that DW doesn't support these regex features.
You can use capturing groups instead (if DW supports it!):
search : (>)\s+(\d)
replace: $1$2
or
replace: \1\2
To append to the previous answer, when formulating a replace statement in DreamWeaver, use the format of $1 rather than ^1 for the variables.
I receive a similar "invalid quantifier" response in DreamWeaver CC 2015.1 when using a negative lookbehind:
(?<!somephrase)
I want to remove inline style from an html document in ST2.
I imagine my regex will be something like this
style=\"*\"
If that's wrong, it doesn't matter. I'm sure I'll figure out the expression I'll need.
What I haven't been able to figure out, is how to actually use a regex to find or to find and replace text in ST2. The docs say that it can be done. But I can't find the documentation for how to do it.
Simply open the Search+Replace function (via Ctrl-H or the menu bar) and check the first box on the left of it (the one with an '*' on it, or you can press Alt+R)
Then the search field will be used as a Regex, and you can use the found patterns using the usual $1, $2, $3 vars in the replace box
More info here
I had a similar task to perform, the regex I used in the manner that Nas62 suggested was
style=\"(.*?)\"
Find What : style=".*" Replace With : leave it as blank
Click Replace All button.
I tried the following regular expression in wingrep 2.3:
[A-Za-z0-9]{1,5}cd77
But the search returns empty, even when I do have the following string testcd77 inside txt file that I am searching.
The Regular Expression Lookup tab on the Search Criteria dialog for my copy of Windows Grep doesn't offer {} as a supported feature. So I think you're stuck with unrolling the search string to
[A-Za-z0-9]([A-Za-z0-9]([A-Za-z0-9]([A-Za-z0-9]([A-Za-z0-9])?)?)?)?cd77
Nothing in the wingrep documentation indicates that they support this kind of interval expression. You might be simply unable to do it.
Some regex engines that do support those expressions require the curly braces to be escaped, so you can try this: [A-Za-z0-9]\{1,5\}cd77. But if that doesn't work then I suspect you are out of luck.
I am trying to find a solution to extract an hyperlink out of every comment which begins with %. My first idea was to use a regular hyperlink regex:
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$
and some kind of pattern like:
%.*
so I added them both to:
^%.*(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$
But with this pattern I match everything, including the % character and multiple spaces. How can I get only the hyperlink inside the comment?
EDIT1:
Here is an example what to parse:
% http://www.test.com
It is a regular MATLAB Comment and i want to highlight it like a hyperlink to get a more intuitive editor. I am working with Qt 4.7.1 / C++
Thanky for all the answers !
I guess it depends a little on the language that is executing your regex, but you could try putting the URL part in parentheses:
%.*((http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s])
That way you can access it as a group (usually an expression such as $1).
I'm looking for a regular expression that can find and replace all the text "anytext" with "anything" in netbeans, some of the symbols also contain this text. I've done it a while back for a single file but now I want to change everything in my application & I'm struggling to get it right.
Just use find & replace to replace all instances of "anytext" with "anything". There is no difference between this and a regex find & replace, because there doesn't exist a pattern that can be easily exploited using regex. There is no difference in this case. Based on your comment, you still must manualy enter the word you want replaced and a word that will replace it.
I think you have misunderstood a bit what regular expressions are all about.
Were you looking for something like this? Where it wouldn't grab it inside word?
\banytext\b