string sentence = "X10 cats, Y20 dogs, 40 fish and 1 programmer.";
string[] digits = Regex.Split (sentence, @"\D+");
for this code i get values in digits array like this 10,20,40,1
string sentence = "X10.4 cats, Y20.5 dogs, 40 fish and 1 programmer.";
string[] digits = Regex.Split (sentence, @"\D+");
for this code i get values i...
I'm new to Python and I have been trying to search through html with regular expressions that has been parsed with BeautifulSoup. I haven't had any success and I think the reason is that I don't completely understand how to set up the regular expressions properly. I've looked at older questions about similar problems but I still haven't ...
I'm using ruby 1.9 and trying to find out which regex I need to make this true:
Encoding.default_internal = Encoding.default_external = 'utf-8'
"föö".match(/(\w+)/u)[1] == "föö"
# => false
...
I have this text file that contains approximately 22 000 lines, with each line looking like this:
12A4 (Text)
So it's in the format 4-letter/number (Hexdecimal) and then text. Sometimes there is more than one value in text, separated by a comma:
A34d (Text, Optional)
Is there any efficient way to search for the Hex and then return the...
Hello,
I have problems determining valid Java package names using Python. Here's the code:
packageName = "com.domain.lala" # valid, not rejected -> correct
#packageName = ".com.domain.lala" # invalid, rejected -> correct
#packageName = "com..domain.lala" # invalid, not rejected -> incorrect
#packageName = "com.domain.la...
Is it possible to find all text inside a node and take the matched text and replace the contents of a node using only a single regular expression? I should say that this is in a file.
Given:
<x>This text</x>
<!-- Unknown number of nodes between <x> and <y> -->
<y>Junk</y>
Change to:
<x>This text</x>
<!-- Unknown number of nodes b...
Hi,
Regular expressions are not my forte and could really do with assistance on matching and replacing the following:
In a HTML file I have many instances of HTML like this:
<font class=font8>text text text</font>
The font tag can have different content in either single word or multiple word with spaces and maybe numbers.
I need to...
I need a regex that matches all instances of a particular PHP function name in given a piece of code.
The regex should match foo in:
foo("qwe");
function foo($param);
return foo();
An not match foo in:
my_foo("qwe");
foo_bar();
"some foo string"
...
How would I add a character to the end of my output? I am scraping some data, I am using a regex to get what I want. I got it but I have to add an 's' to the end of the sentence.
The sentence changes every time so I can't just do a replace. I think I am using the .NET regex engine.
...
This is the regex i'm trying to use:
/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim
I found it on this site, and it works great when i try it out there. But as soon as i place it in my code i get this message:
Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\xampp\htdocs\swebook\includes\classes.php on line ...
I have the following XML:
<id>tag:search.twitter.com,2005:22204349686</id>
How can i write everything after the second colon to a variable?
E.g. 22204349686
...
I have the following RegEx to replace the entire querystring for a string with a new one:
"http://www.google.com?bar=1".replace(/\?.*/, "?foo=2")
This works only if there is a querystring. The following will not work:
"http://www.google.com".replace(/\?.*/, "?foo=2")
How do I make the RegEx match both situations?
...
I am trying to create a number range given a regex. This is the opposite of most questions in trying to validate if a number is in a range. I am going to be given the regex and need to create the range.
For example, given the regex "80055510[34]X" I would like to create the numbers 8005551030 through 8005551049. The "X" can be whatever,...
hi,
how do I write an expression which checks for lowcaps, dots, and without any white space in the string?
the code below so far was trying to check for lowcaps and dots (it does not work anyway!) but I don't know how to add in the expression for white spaces.
# check for matches of lowcaps or lowcaps with a dot
if (!preg_match('/([a...
Can someone explain why this code doesn't work as expected?
I would expect it only to match the first character, and it does with literal characters, but the wildcard (.) and characters classes behave strangely:
I use -o just to demonstrate exactly how things are matching, it doesn't change what matches at all.
$ echo foo | grep -o '^....
i cells that look like this: one per line:
Duffy,John: 'Heritage: Civilization and the Jews'- Fanfare & Chorale,Symphonic Dances + Orchestral Suite. Bernstein,'On the Town' Dance Episodes. Royal Phil./R.Williams
Lilien,Ignace 1897-1963: Songs,1920-1935. Anja van Wijk,mezzo & Frans van Ruth,piano
Hindemith,Trauermusik. Purcell,'Fairy Que...
Hi!
I'm trying to store regexes in a database but they're getting escaped by rails.
For example \w*\s\/\s becomes \\w*\\s\\/\\s in the database and when retrieved.
I'm inserting trying to use them with mystring.sub(/#{regex_variable}/, ''), but the escaped regex is not matching as desired.
What's the best we to resolve this so the r...
I'm trying to replace all instances of a word, say "foo" between some HTML tags.
<span id=foo> blah blah foo blah foo blah </span>
I want to replace all instances of foo that are not in the tag with bar, so the end result is:
<span id=foo> blah blah bar blah bar blah </span>
Notice that "foo" in the span tag has not been replaced....
Hello guys,
I'm porting the rewrite rules of shimmie2 to nginx and ran across a problem:
From the first impression it worked quite well, but when you try to view the image (I mean via right-click menu in your browser) you end up with stuff like this, instead the original image:
ÿØÿà�JFIF��H�H��ÿÛ�C�
ÿÛ�CÿÀ���À�ÿÄ�����������...
I want to run:
> ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29034) [x86_64-darwin10.4.0]
and then see if 1.9.2 is printed out. If so, i return true.
How would this method look like using a regexp?
...