From the  it says that:  Pattern.match(...)     If zero or more characters at the beginning of string match this regular expression   Pattern.fullmatch(...)     If the whole string matches this regular expression   Pattern.search(...)     Scan through string looking for the first location where this regular expression produces a match   Given the above, why couldn't someone just always use search to do everything? For example:  re.search(r'...'   # search re.search(r'^...'  or re.search(r'\A...'   # match re.search(r'^...$' or re.search(r'\A...\Z' # fullmatch   Are match and fullmatch just shortcuts (if they could be called that) for the search method? Or do they have other uses that I'm overlooking?
372
What is the difference between the search() and match() functions in the ?  I've read the  (), but I never seem to remember it.  I keep having to look it up and re-learn it.  I'm hoping that someone will answer it clearly with examples so that (perhaps) it will stick in my head.  Or at least I'll have a better place to return with my question and it will take less time to re-learn it.
2940
How can I test if a RegEx matches a string exactly?  var r = /a/; r.test("a"); // returns true r.test("ba"); // returns true testExact(r, "ba"); // should return false testExact(r, "a"); // should return true
104262
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 get partial matches but because a section in quotes can contain any characters it quickly expands to match the whole statement.  Any help would be appreciated, I'm not very good with regular expressions but I'd like to learn more about them.  By the way it's C# RegEx that I'm after.  Clarification  I don't want to need access to a database as this is part of a Unit test and I don't wan't to have to maintain a database to test my code. which may live longer than the project.
10243
I'm quite confused about the following regular expressions I found in a shell script:  ${0##*/} ${0%/*}   How do they work?
66513
Is there a way to debug a regular expression in Python? And I'm not referring to the process of trying and trying till they work :)  Here is how regexes can be debugged in Perl:   use re 'debug';  my $str = "GET http://some-site.com HTTP/1.1"; if($str =~/get\s+(\S+)/i) {     print "MATCH:$1\n"; }   The code above produces the following output on my computer when ran:   Compiling REx "get\s+(\S+)" Final program:    1: EXACTF  (3)    3: PLUS (5)    4:   SPACE (0)    5: OPEN1 (7)    7:   PLUS (9)    8:     NSPACE (0)    9: CLOSE1 (11)   11: END (0) stclass EXACTF  minlen 5 Matching REx "get\s+(\S+)" against "GET http://some-site.com HTTP/1.1" Matching stclass EXACTF  against "GET http://some-site.com HTTP/1.1" (33 chars)    0           |  1:EXACTF (3)    3        |  3:PLUS(5)                                   SPACE can match 1 times out of 2147483647...    4       |  5:  OPEN1(7)    4       |  7:  PLUS(9)                                     NSPACE can match 20 times out of 2147483647...   24       |  9:    CLOSE1(11)   24       | 11:    END(0) Match successful! MATCH:http://some-site.com Freeing REx: "get\s+(\S+)"
42865
Can anyone help me with this question: I know it before, but I have tried to solve it myself and didnt succeed. what is the regular expression for this language: L=all words that have 00 or 11 but not both.  Thank you!
115440
Simply said, I just can't find a way to match a variable against some pattern containing spaces.  Here is what I expected to work (echo 'ok' string)  item='foobar baz' pat=".+bar baz" if [[ "$item" =~ "$pat" ]] ; then     echo ok fi   Adding/removing quotes around $pat does not seem to make any difference. I get those two erros below:  bash: conditional binary operator expected bash: syntax error near `~='   Could someone please help me pointing out what I am doing wrong here ? Should I put the pattern right away (without any quotes/double quotes, nor variable reference) ? If that is the case, then how can I put spaces in ? (using reg-exp matching, not an alternative)  Thank you !
30489
I have a Python regular expression that contains a group which can occur zero or many times - but when I retrieve the list of groups afterwards, only the last one is present. Example:  re.search("(\w)*", "abcdefg").groups()  this returns the list ('g',)  I need it to return ('a','b','c','d','e','f','g',)  Is that possible? How can I do it?
108459
Are Python and JavaScript regular expression syntax identical?   If not, then:    What are the important differences between them Is there a python library that "implements" JavaScript regexps?
102259
I need to search a string in the string array. I dont want to use any for looping in it  string [] arr = {"One","Two","Three"};  string theString = "One"   I need to check whether theString variable is present in arr.
1430
I want to check whether Value1 below contains "abc" within the first X characters. How would you check this with an if statement?  var Value1 = "ddabcgghh";  if (Value1.Contains("abc")) {     found = true; }   It could be within the first 3, 4 or 5 characters.
26992
I have this file:  sometext1{ string1 }  sometext2{ string2 string3 }  sometext3{ string4 string5 string6 }   I want to search this file for a specific string and print everything before this string up to the opening { and everything after this string up to the closing }. I tried to achieve this with sed but if I try to print everything in the range /{/,/string2/ for example sed prints this:  sometext1{ string1 }  sometext2{ string2 sometext3{ string4 string5 string6 }   If I search for the string "string2" I need the output to be:   sometext2{ string2 string3 }   Thanks.
10465
Please support the use of nested expressions like  and (or ) when searching.  Looking here, on meta, at questions tagged   and at questions found with +search +tag +boolean I didn't see any information on this topic.
8877
I've seen lots of examples of making an entire regular expression case-insensitive.  What I'm wondering about is having just part of the expression be case-insensitive.  For example, let's say I have a string like this:  fooFOOfOoFoOBARBARbarbarbAr   What if I want to match all occurrences of "foo" regardless of case but I only want to match the upper-case "BAR"s?  The ideal solution would be something that works across regex flavors but I'm interested in hearing language-specific ones as well (Thanks )  Edit  The link Espo provided was very helpful.  There's a good example in there about turning modifiers on and off within the expression.  For my contrived example, I can do something like this:  (?i)foo*(?-i)|BAR   which makes the match case-insensitive for just the foo portion of the match.  That seemed to work in most regex implementations except Javascript, Python, and a few others (as Espo mentioned).    The big ones that I was wondering about (Perl, PHP, .NET) all support inline mode changes.
47023
Say I have the string "User Name:firstname.surname" contained in a larger string how can I use a regular expression to just get the firstname.surname part?  Every method i have tried returns the string "User Name:firstname.surname" then I have to do a string replace on "User Name:" to an empty string.  Could back references be of use here?  Edit:  The longer string could contain "Account Name: firstname.surname" hence why I want to match the "User Name:" part of the string aswell to just get that value.
35188
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?  Edit: I work in python. But would like to know in general about most popular languages/tools (java, perl, sed).
12909
I'm using RegexBuddy but I'm in trouble anyway with this thing :\  I'm processing line by line a file. I built a "line model" to match what I want.  Now i'd like to do an inverse match... i.e. I want to match lines where there is a string of 6 letters, but only if these six letters are not Andrea, how should I do that?    EDIT: I'll write the program that uses this regex, I don't know yet if in python or php, I'm doing this thing first to learn some regex :) There are different types of line, I wanted to use regex to select the type i'm interested in. Once I got these lines I've to apply an other filter just to do not match a known value, I need all the others, not that. The (?!not-wanted) is working pretty fine, thank you. :-)  I hope this clarifies the question :)