I need to increment a number in a source file from an ant build script. I can use the ReplaceRegExp task to find the number I want to increment, but how do I then increment that number within the replace attribute?
Heres what I've got so far:
<replaceregexp file="${basedir}/src/path/to/MyFile.java"
match="MY_PROPERTY = ([0-9]{1,});...
Wanted to convert
<br/>
<br/>
<br/>
<br/>
<br/>
into
<br/>
...
Is it possible to write a regular expression that matches a nested pattern that occurs an unknown number of times. For example, can a regular expression match an opening and closing brace when there are an unknown number of open closing braces nested within the outer braces.
For example:
public MyMethod()
{
if (test)
{
// More ...
Lexical analyzers are quite easy to write when you have regexes. Today I wanted to write a simple general analyzer in Python, and came up with:
import re
import sys
class Token(object):
""" A simple Token structure.
Contains the token type, value and position.
"""
def __init__(self, type, val, pos):
self.ty...
Examples:
"1" yes
"-1" yes
"- 3" no
"1.2" yes
"1.2.3" no
"7e4" no (though in some cases you may want to allow scientific notation)
".123" yes
"123." yes
"." no
"-.5" yes
"007" yes
"00" yes
...
Let's say I want to write a regular expression to change all <abc>, <def>, and <ghi> tags into <xyz> tags.. and I also want to change their closing tags to </xyz>. This seems like a reasonable regex (ignore the backticks; StackOverflow has trouble with the less-than signs if I don't include them):
`s!<(/)?(abc|def|ghi)>!<${1}xyz>!g;`
...
I'm searching for UUIDs in blocks of text using a regex. Currently I'm relying on the assuming that all UUIDs will follow a patttern of 8-4-4-4-12 hexadecimal digits.
Can anyone think of a use case where this assumption would be invalid and would cause me to miss some UUIDs?
...
I'm having trouble coming up with the correct regex string to remove a sequence of multiple ? characters. I want to replace more than one sequential ? with a single ?, but which characters to escape...is escaping me.
Example input:
Is this thing on??? or what???
Desired output:
Is this thing on? or what?
I'm using preg_repla...
I decide to learn more about vim and its syntax highlighting.
Using examples for others, I am creating my own syntax file for Markdown. I have seen mkd.vim and it has this problem too.
My issue is between list items and code block highlighting.
Code Block definition:
first line is blank
second line begins with at least 4 spaces or 1 t...
I would like to create a page where all images which reside on my website are listed with title and alternative representation.
I already wrote me a little program to find and load all html files, but now I am stuck at how to extract src, title and alt from the html
< img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a ...
I need to replace character (say) x with character (say) P in a string, but only if it is contained in a quoted substring.
An example makes it clearer:
axbx'cxdxe'fxgh'ixj'k -> axbx'cPdPe'fxgh'iPj'k
Let's assume, for the sake of simplicity, that quotes always come in pairs.
The obvious way is to just process the string one characte...
I'm trying to learn Regex in Ruby, based on what I'm reading in "The Rails Way". But, even this simple example is stumping me. I can't tell if it is a typo or not...
text.gsub(/\s/, "-").gsub([^\W-], '').downcase
It seems to me that this would replace all spaces with -, then anywhere a string starts with a non letter or number followed...
Possibly a lame question. But I've yet to find an answer to it.
Currently I use .Net WebBrowser.Document.Images() to do this.
It requires the Webrowser to load the document. Its messy and takes up resources.
According to this Question Xpath is better than a regex at this.
Anyone know how to do this in C#?
Thanks
...
I was writing some Unit tests last week for a piece of code that generated some SQL statements.
I was trying to figure out a regex to match SELECT,INSERT and UPDATE syntax so I could verify that my methods were generating valid SQL, and after 3-4 hours of searching and messing around with various regex editors I gave up.
I managed to g...
When using regular expressions we generally, if not always use them to extract some kind of information. What I need is to replace the match value with some other value...
Right now I'm doing this...
def getExpandedText(pattern, text, replaceValue):
"""
One liner... really ugly but it's only used in here.
"""
retu...
I want to replace the first occurrence in a given string.
How can I accomplish this in .NET?
...
What's the best and most efficient way to count keywords in JavaScript? Basically, I'd like to take a string and get the top N words or phrases that occur in the string, mainly for the use of suggesting tags. I'm looking more for conceptual hints or links to real-life examples than actual code, but I certainly wouldn't mind if you'd like...
My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:
This input:
<%"TITLE"="This Is A Test Variable"%>The Web <%"TITLE"%>
Should produce this output:
The Web This Is A Test Variable
I've got it working. But looking at my code, I'm running multi...
I currently have a fairly robust server-side validation system in place, but I'm looking for some feedback to make sure I've covered all angles. Here is a brief outline of what I'm doing at the moment:
Ensure the input is not empty, or is too long
Escape query strings to prevent SQL injection
Using regular expressions to reject invalid...
ex: <a><strike>example data in here</strike></a>
I want everything inside the a tag, to the end
/<a>([^<]*)<\/a>/
It works when there are no additional tags within the <a> tag, but what if there are?
I want to know if you can tell it to grab everything up to [^</a>] instead of [^<] only.
Doing it with /<a>(.*)<\/a>/ doesn't wor...