regex

PHP Get Source and Search for Word

I need help i want to code a program that search for a word inside the source code. Here a Example in Python: import urllib2, re site = "http://stackoverflow.com/" tosearch = "Questions" source = urllib2.urlopen(site).read() if re.search(tosearch,source): print "Found The Word", tosearch ...

Regex help needed in javascript

Hi, First question on here so please be nice :) I know very little about regular expressions but I am using one in a current project which strips special characters from a string. It looks like this... newWord = newWord.replace(/[^0-9A-Za-z ]/g, ""); It works well, but I need to modify it slightly so that it doesn't remove the £ (GB...

Is it worth using Python's re.compile?

Is there any benefit in using compile for regular expressions in Python? h = re.compile('hello') h.match('hello world') vs re.match('hello', 'hello world') ...

Can anyone explain this .ASP aka VB "Regex.Replace" function so that I can do it in PHP?

Hi, The following code is visual basic, .NET, ASP... all of the above? Can anybody tell me what these two "Regex.Replace" functions/methods will leave me with when "strCookies" is equal to the block of text below the two Regex.Replace functions? I believe the idea is simply to capture the "sessionid" code and then the "cadata" code with ...

PHP/RegEx - Logic for prepending table names

So I'm trying to build a script that automagically prepends valid column names with its appropriate table prefix (e.g. "t." or "r.") $t_columns = array('id', 'name', 'label'); $r_columns = array('related_value'); INPUT: id > 1 AND (name = 'Hello' OR label IN ('World', 'Planet name AND label')) AND (related_value > 1 AND related_value...

How can I find a string after a specific string/character using regex

Hi, I am hopeless with regex (c#) so I would appreciate some help: Basicaly I need to parse a text and I need to find the following information inside the text: Sample text: KeywordB:TextToFind the rest is not relevant but KeywordB: Text ToFindB and then some more text. I need to find the word(s) after a certain keyword which may en...

How do I re.search or re.match on a whole file without reading it all into memory?

I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks! Clarification: I cannot read line-by-line because it can span multiple lines. ...

RE -> FSM generator?

Given a regular expression, I'm looking for a package which will dynamically generate the code for a finite state machine that implements the RE. C/C++ and Python preferred, but other languages are of interest as well. ...

Split Java String by New Line

I'm trying to split text in a JTextArea using a regex to split the String by \n However, this does not work and I also tried by \r\n|\r|n and many other combination of regexes. Code: public void insertUpdate(DocumentEvent e) { String split[], docStr = null; Document textAreaDoc = (Document)e.getDocument(); try { doc...

XSLT RegEx: replace HTML tags in CDATA

Hi I want to replace some HTML tags that I have in a CDATA element, but I struggle with getting the syntax in XSLT right. I am getting this error message: net.sf.saxon.trans.XPathException: Error at character 9 in regular expression "<img(\s+(?![^<>]*alt=["\'])[^<...": expected ()) (line 51) I guess it does not like the <> inside th...

regex for finding method that have the expression

I try to find methods that have expression createNamedQuery I try public[\d\D]*?createNamedQuery but it finds the first method, but i want the method that has expression createNamedQuery ...

Regular Expression Help

I am trying to find all of the links in source code on a website, could anyone tell me the expression i would need to put in my Regex to find these? Duplicate of (among others): Regular expression for parsing links from a webpage? Google finds more: html links regex site:stackoverflow.com ...

Can you use Boost.Regex to parse a stream?

I was playing around with Boost.Regex to parse strings for words and numbers. This is what I have so far: #include <iostream> #include <string> #include <boost/foreach.hpp> #include <boost/regex.hpp> #include <boost/range.hpp> using namespace std; using namespace boost; int main() { regex re ( "(" "([a-z]+)...

What is the best way to find and replace urls on a giant text?

I have I huge backup of posts of my blog. All posts has images like: "http://www.mysite.com/nonono-nonono.jpg" or "http://www.mysite.com/nonono-nonono.gif" or even "http://www.mysite.com/nonono.jpg" But I have other links for urls on the same domain like ""http://www.mysite.com/category/post.html" and I just want to replace urls...

Infinite matching of a subexpressions (regular expressions) returns only one match

I have a regular expression like this (much simplified): ^(ab)*$ And am matching against this: abababababababab When I run it through preg_match: preg_match('/$(ab)*$/', 'abababababababab', $matches); print_r($matches); I get this: Array ( [0] => abababababababab [1] => ab ) Wheras I expect this: Array ( [0] => a...

Regex for parsing tags from a string.. Flickr style

I wonder if anyone can provide me with the regular expressions needed to parse a string like: 'foo bar "multiple word tag"' into an array of tags like: ["foo","bar","multiple word tag"] Thanks ...

RegEx for allowing alphanumeric at the starting and hyphen thereafter

I had a requirement where in the text field the first character should be a alpha numeric and then i can allow a hyphen from thereafter in JavaScript.Also hyphen should not be allowed at the end ...

Using an asterisk in a RegExp to extract data that is enclosed by a certain pattern

Hi. I have an text that consists of information enclosed by a certain pattern. The only thing I know is the pattern: "${template.start}" and ${template.end} To keep it simple I will substitute ${template.start} and ${template.end} with "a" in the example. So one entry in the text would be: aINFORMATIONHEREa I do not know how many o...

Parsing text from the end (using regular expressions)

Hi, I have a seemingly simple problem though i am unable to get my head around it. Let's say i have the following string: 'abcabcabcabc' and i want to get the last occurrence of 'ab'. Is there a way i can do this without looping through all the other 'ab's from the beginning of the string? I read about anchoring the end of the string ...

RegEx match replace help

I am trying to do a regex match and replace for an .htaccess file but I can't quite figure out the replace bit. I think I have the match part right, but maybe someone can help. I have this url- http://www.foo.com/MountainCommunities/Lifestyles/5/VacationHomeRentals.aspx And I'm trying to turn it into this- http://www.foo.com/mountain-l...