Search Results

Search found 3804 results on 153 pages for 'regex lookarounds'.

Page 1/153 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • c# RegEx with "|"

    - by WtFudgE
    I need to be able to check for a pattern with | in them. For example an expression like d*|*t should return true for a string like "dtest|test". I'm no regex hero so I just tried a couple of things, like: Regex Pattern = new Regex("s*\|*d"); //unable to build because of single backslash Regex Pattern = new Regex("s*|*d"); //argument exception error Regex Pattern = new Regex(@"s*\|*d"); //returns true when I use "dtest" as input, so incorrect Regex Pattern = new Regex(@"s*|*d"); //argument exception error Regex Pattern = new Regex("s*\\|*d"); //returns true when I use "dtest" as input, so incorrect Regex Pattern = new Regex("s*" + "\\|" + "*d"); //returns true when I use "dtest" as input, so incorrect Regex Pattern = new Regex(@"s*\\|*d"); //argument exception error I'm a bit out of options, what should I then use? I mean this is pretty basic RegEx i know, but I'm not getting it for some reason.. Thx

    Read the article

  • Use RegEx in Java to extract parameters in between parentheses

    - by lars_bx
    I'm writing a utility to extract the names of header files from JSPs. I have no problem reading the JSPs line by line and finding the lines I need. I am having a problem extracting the specific text needed using regex. After looking at many similar questions I'm hitting a brick wall. An example of the String I'll be matching from within is: <jsp:include page="<%=Pages.getString(\"MY_HEADER\")%>" flush="true"></jsp:include> All I need is MY_HEADER for this example. Any time I have this tag: <%=Pages.getString I need what comes between this: <%=Pages.getString(\" and this: )%> Here is what I have currently (which is not working, I might add) : String currentLine; while ((currentLine = fileReader.readLine()) != null) { Pattern pattern = Pattern.compile("<%=Pages\\.getString\\(\\\\\"([^\\\\]*)"); Matcher matcher = pattern.matcher(currentLine); while(matcher.find()) { System.out.println(matcher.group(1).toString()); }} I need to be able to use the Java RegEx API and regex to extract those header names. Any help on this issue is greatly appreciated. Thanks! EDIT: Resolved this issue, thankfully. The tricky part was, after being given the right regex, it had to be taken into account that the String I was feeding to the regex was always going to have two " / " characters ( (/"MY_HEADER"/) ) that needed to be escaped in the pattern. Here is what worked (thanks to the help ;-)): Pattern pattern = Pattern.compile("<%=Pages\\.getString\\(\\\\\"([^\\\\\"]*)");

    Read the article

  • A pattern matching an expression that doesn't end with specific sequence

    - by patryk
    I need a regex pattern which matches such strings that DO NOT end with such a sequence: \.[A-z0-9]{2,} by which I mean the examined string must not have at its end a sequence of a dot and then two or more alphanumeric characters. For example, a string /home/patryk/www and also /home/patryk/www/ should match desired pattern and /home/patryk/images/DSC002.jpg should not. I suppose this has something to do with lookarounds (look aheads) but still I have no idea how to make it. Any help appreciated.

    Read the article

  • Make a Perl-style regex interpreter behave like a basic or extended regex interpreter

    - by Barry Brown
    I am writing a tool to help students learn regular expressions. I will probably be writing it in Java. The idea is this: the student types in a regular expression and the tool shows which parts of a text will get matched by the regex. Simple enough. But I want to support several different regex "flavors" such as: Basic regular expressions (think: grep) Extended regular expressions (think: egrep) A subset of Perl regular expressions, including the character classes \w, \s, etc. Sed-style regular expressions Java has the java.util.Regex class, but it supports only Perl-style regular expressions, which is a superset of the basic and extended REs. What I think I need is a way to take any given regular expression and escape the meta-characters that aren't part of a given flavor. Then I could give it to the Regex object and it would behave as if it was written for the selected RE interpreter. For example, given the following regex: ^\w+[0-9]{5}-(\d{4})?$ As a basic regular expression, it would be interpreted as: ^\\w\+[0-9]\{5\}-\(\\d\{4\}\)\?$ As an extended regular expression, it would be: ^\\w+[0-9]{5}-(\\d{4})?$ And as a Perl-style regex, it would be the same as the original expression. Is there a "regular expression for regular expressions" than I could run through a regex search-and-replace to quote the non-meta characters? What else could I do? Are there alternative Java classes I could use?

    Read the article

  • Recommendation for Regex editor?

    - by Tim
    I asked for recommendations for Regex editors on stackoverflow a while ago. Following is one of the replies: What is "good" depends on what is most useful to you. For me, though, these are the key features for a good regex editor (besides the ability to test and create regular expressions, of course, which is a prerequisite to be called a "regex editor" :-) : Displays matches hierarchically with captured groups. Explains/analyzes an entered regex in plain English, showing a hierarchical tree. Translates your regex into code for a language of your choice. RegexBuddy, as @Max mentioned, does all these but there is also a free alternative, Expresso that also does them very well. These two utilities are the only ones I have found with the crucial ability to explain a regex. The features sound very attractive to me. But later I found the two are for Windows. I tried to install Expresso, the free one, via Wine, but met some trouble, about which I asked in another post. So I was wondering if in Ubuntu there are some applications comparable to RegexBuddy and Expresso? If it is required to install .NET Framework in order to install Expresso, is it still worth to install Expresso on Ubuntu? Thanks and regards!

    Read the article

  • How to negate the whole regex?

    - by 01
    I have a regex, for example ([m]{2}|(t){1}). It matches ma and t and doesn't match bla. I want to negate the regex, thus it must match bla and not ma and t, by adding something to this regex. I know I can write bla, the actual regex is however more complex.

    Read the article

  • c# Regex trouble

    - by Shannow
    Hi there, I'm having a bit of trouble with my regex. String a = @"{target=}jump"; String b = "continue"; String c = "jump"; String d = @"{target=intro}jump"; String e = "prev"; String f = @"{target=}choice"; String g = @"{target=intro}choice"; String h = "choice"; String i = "previous"; String j = @"{target=intro}continue"; String k = "cont"; String l = @"{target=}continue"; Regex regex = new Regex(@"(^{target=(\w.*)}(choice|jump))|(^[^.]*(continue|previous))"); var a_res = regex.IsMatch(a); var b_res = regex.IsMatch(b); var c_res = regex.IsMatch(c); var d_res = regex.IsMatch(d); var e_res = regex.IsMatch(e); var f_res = regex.IsMatch(f); var g_res = regex.IsMatch(g); var h_res = regex.IsMatch(h); var i_res = regex.IsMatch(i); var j_res = regex.IsMatch(j); var k_res = regex.IsMatch(k); var l_res = regex.IsMatch(l); Basically what i need is to get a match when choice or jump is present that it is proceeded by {target= } with any number of characters after the =. And also to match if continue or previous are present but only if they are proceeded by nothing. so A = false, b = true, c = false, d = true, e = false, f = false, g = true, h = false, i = true, j = false, k = false and l = false, with my regex above I get correct reading for everything bar j and l. Can anyone please help?

    Read the article

  • Building a regex builder

    - by i.h4d35
    I am a beginner in programming in general and web development in particular. I am especially bad at regular expressions. Recently I was involved in building a couple of cPanel plugins(Perl-CGI) and that's when I realized how bad I am in regex. As a result, I have decided to build an online regex builder - this will help me to learn regex and help other struggling with regex. I have checked out GSkinner, Rubular and a couple of others like regexpal. It seemed to be a little difficult to use, hence i thought of writing another one. I do not know which tool is best suited for the job. should I write it in Perl or Python? My skill level is between beginner and intermediate in both those languages. What would be a good starting point - building it for the CLI or for the browser? I plan to get a string as an input, ask if the user want to search or search and replace, enter the search string (and the replace string where applicable) and then generate a regex. Would this be the right way to go?

    Read the article

  • how to negate whole regex ??

    - by 01
    I have regex (for example) ([m]{2}|(t){1}) and it matches ma and t and doesnt match bla I want it to match bla and doesnt match ma and t by adding something to this regex, i know i can write bla, my real-life regex is more complex.

    Read the article

  • Why is negation of a regex needed?

    - by Lazer
    There are so many questions on regex-negation here on SO. I am not sure I understand why people feel the need to negate a regex. Why not use something like grep -v that shows only the results that do not match the regex? $ ls april august december february january july june march may november october september $ ls | grep ber december november october september $ ls | grep -v ber april august february january july june march may

    Read the article

  • Regex to match a whole string only if it lacks a given substring/suffix

    - by Ivan Krechetov
    I've searched for questions like this, but all the cases I found were solved in a problem-specific manner, like using !g in vi to negate the regex matches, or matching other things, without a regex negation. Thus, I'm interested in a “pure” solution to this: Having a set of strings I need to filter them with a regular expression matcher so that it only leaves (matches) the strings lacking a given substring. For example, filtering out "Foo" in: Boo Foo Bar FooBar BooFooBar Baz Would result in: Boo Bar Baz I tried constructing it with negative look aheads/behinds (?!regex)/(?<!regex), but couldn't figure it out. Is that even possible?

    Read the article

  • Boost Regex unknown number of var

    - by Katrin Thielmann
    I got a Problem with a regex expression and need help. I have some expressions like these in mein .txt File: 19 = NAND (1, 19) regex expression : http://rubular.com/r/U8rO09bvTO With this regex expression i got seperated matches for the numbers. But now I need a regex expression with a unknown size of numbers in the bracket . For example: 19 = NAND (1, 23, 13, 24) match1: 19 match2: 1 match3: 23 match4: 13 match5: 24 I don't know the number of the numbers. So i need a main expression for min 2 numbers in the bracket till a unknow number. I hope somebody can help me.

    Read the article

  • Regex to leave desired string remaining and others removed

    - by m7d
    In Ruby, what regex will strip out all but a desired string if present in the containing string? I know about /[^abc]/ for characters, but what about strings? Say I have the string "group=4&type_ids[]=2&type_ids[]=7&saved=1" and want to retain the pattern group=\d, if it is present in the string using only a regex? Currently, I am splitting on & and then doing a select with matching condition =~ /group=\d/ on the resulting enumerable collection. It works fine, but I'd like to know the regex to do this more directly.

    Read the article

  • Haskell: 'No instance for' arising from a trivial usage of Regex library

    - by artemave
    Following the (accepted) answer from this question, I am expecting the following to work: Prelude Text.Regex.Posix Text.Regex.Base.RegexLike Text.Regex.Posix.String> makeRegex ".*" (makeRegex is a shortcut for makeRegexOpts with predefined options) However, it doesn't: <interactive>:1:0: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at <interactive>:1:0-13 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex ".*" In the definition of `it': it = makeRegex ".*" Prelude Text.Regex.Posix Text.Regex.Base.RegexLike Text.Regex.Posix.String> make Regex ".*"::Regex <interactive>:1:0: No instance for (RegexMaker Regex compOpt execOpt [Char]) arising from a use of `makeRegex' at <interactive>:1:0-13 Possible fix: add an instance declaration for (RegexMaker Regex compOpt execOpt [Char]) In the expression: makeRegex ".*" :: Regex In the definition of `it': it = makeRegex ".*" :: Regex And I really don't understand why. EDIT Haskell Platform 2009.02.02 (GHC 6.10.4) on Windows EDIT2 Prelude Text.Regex.Base.RegexLike Text.Regex.Posix.String> :i RegexMaker class (RegexOptions regex compOpt execOpt) => RegexMaker regex compOpt execOpt source | regex -> compOpt execOpt, compOpt -> regex execOpt, execOpt -> regex compOpt where makeRegex :: source -> regex makeRegexOpts :: compOpt -> execOpt -> source -> regex makeRegexM :: (Monad m) => source -> m regex makeRegexOptsM :: (Monad m) => compOpt -> execOpt -> source -> m regex -- Defined in Text.Regex.Base.RegexLike

    Read the article

  • OWASP Regex Repository: Is this regex correct?

    - by Jacco
    I was looking at the regular expression for validating various data types from the (OWASP Regex Repository). One of the regular expressions in there is called safetext and looks like: ^[a-zA-Z0-9\s.\-]+$ My first question is: Is this regular expression correct? complementary question If this Regex Repository any good at all?

    Read the article

  • regex return conditional group

    - by priyank.mp
    Hi , I spent lot time figuring out a simple regex to return a group (only 1st group). So the string can be - "No purchase required" or "Purchase of $50.00 worth groceries is required." I am trying to write a regex which can parse "No" or "50" based on the given string. This is what I have written. (?:(No) monthly maintenance|Purchase of \$([\d\.]+ worth groceries) This works fine but I want my output as 1st group/group 1 only.

    Read the article

  • Find multiple regex in each line and skip result if one of the regex doesn't match

    - by williamx
    I have a list of variables: variables = ['VariableA', 'VariableB','VariableC'] which I'm going to search for, line by line ifile = open("temp.txt",'r') d = {} match = zeros(len(variables)) for line in ifile: emptyCells=0 for i in range(len(variables)): regex = r'('+variables[i]+r')[:|=|\(](-?\d+(?:\.\d+)?)(?:\))?' pattern_variable = re.compile(regex) match[i] = re.findall(pattern_variable, line) if match[j] == []: emptyCells = emptyCells+1 if emptyCells == 0: for k, v in match[j]: d.setdefault(k, []).append(v) The requirement is that I will only keep the lines where all the regex'es matches! I want to collect all results for each variable in a dictionary where the variable name is the key, and the value becomes a list of all matches. The code provided is only what I've found out so far, and is not working perfectly yet...

    Read the article

  • Vim Regex to replace tags

    - by Rudiger Wolf
    I am lookin for a regex express to remove the email addresses from a text file. Input file: Hannah Churchman <[email protected]>; Julie Drew <[email protected]>; Output file: Hannah Churchman; Julie Drew; I thought a generic regex shuch as s/<(.*?)//g would be a good starting point but I am unable to find the right expression for use Vim? something like :%s/ <\(.*?\)>//g does not work. Error is "E486: Pattern not found:". :%s#[^ <]*>##g almost works but it leaves the space and < behind. :%s# <##g to remove the " <" remaining stuff. Any tips on how to better craft this command?

    Read the article

  • Complex(?) regex: Is expression, but not another

    - by Kieron
    (If you can make a better title, please do) Hi, I need to make sure a string matches the following regex: ^[0-9a-zA-Z]{1}[0-9a-zA-Z\.\-_]*$ (Starts with a letter or number, then any number of letters, numbers, dots, dashes or underscores) But given that, I need to make sure it doesn't match a Guid, my Guid matching reg-ex looks like this (obviously, this needs to be negated in the merged result): ^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$ The last requirement here is that they must (if it's possible) be merged into a single expression.

    Read the article

  • JS regex isn't matching, even thought it works with a regex tester

    - by Tom O
    I'm writing a piece of client-side javascript code that takes a function and finds the derivative of it, however, the regex that's supposed to match with the power rule fails to work in the context of the javascript program, even though it sucessfully matches when it's used with an independent regex tester. The browser I'm executing this on is Midori, and the operating system is Ubuntu 10.04 (Lucid Lynx). Here's the HTML page being used as the interface in addition to the code: Page: <html> <head> <title> Derivative Calculator </title> <script type="text/javascript" src="derivative.js"> </script> <body> <form action="" name=form> <input type=text name=f /> with respects to <input type=text name=vr size=7 /> <input type=button value="Derive!" onClick="main(this.form)" /> <br /> <input type=text name=result value="" /> </form> </body> </html> derivative.js: function main(form) { form.result.value = derive(form.f.value, form.vr.value); } function derive(f, v) { var atom = []; atom["sin(" + v + ")"] = "cos(" + v + ")"; atom["cos(" + v + ")"] = "-sin(" + v + ")"; atom["tan(" + v + ")"] = "sec^(2)(" + v + ")"; atom["sec(" + v + ")"] = "sec(" + v + ")*tan(" + v + ")"; atom["1/(cos(" + v + "))"] = "sec(" + v + ")*tan(" + v + ")"; atom["csc(" + v + ")"] = "-csc(" + v + ")*cot(" + v + ")"; atom["1/(sin(" + v + "))"] = "-csc(" + v + ")*cot(" + v + ")"; atom["cot(" + v + ")"] = "-csc^(2)(" + v + ")"; atom["1/(tan(" + v + "))"] = "-csc^(2)(" + v + ")"; atom["sin^(-1)(" + v + ")"] = "1/sqrt(1 - " + v + "^(2))"; atom["arcsin(" + v + ")"] = "1/sqrt(1 - " + v + "^(2))"; atom["cos^(-1)(" + v + ")"] = "-1/sqrt(1 - " + v + "^(2))"; atom["arccos(" + v + ")"] = "-1/sqrt(1 - " + v + "^(2))"; atom["tan^(-1)(" + v + ")"] = "1/(1 + " + v + "^(2))"; atom["arctan(" + v + ")"] = "1/(1 + " + v + "^(2))"; atom["sec^(-1)(" + v + ")"] = "1/(|" + v + "|*sqrt(" + v + "^(2) - 1))"; atom["arcsec(" + v + ")"] = "1/(|" + v + "|*sqrt(" + v + "^(2) - 1))"; atom["csc^(-1)(" + v + ")"] = "-1/(|" + v + "|*sqrt(" + v + "^(2) - 1))"; atom["arccsc(" + v + ")"] = "-1/(|" + v + "|*sqrt(" + v + "^(2) - 1))"; atom["cot^(-1)(" + v + ")"] = "-1/(1 + " + v + "^(2))"; atom["arccot(" + v + ")"] = "-1/(1 + " + v + "^(2))"; atom["ln(" + v + ")"] = "1/(" + v + ")"; atom["e^(" + v + ")"] = "e^(" + v + ")"; atom["ln(|" + v + "|)"] = "1/(" + v + ")"; atom[v] = "1"; var match = ""; if (new Boolean(atom[f]) == true) { return atom[f]; } else if (f.match(/^[0-9]+$/)) { return ""; } else if (f.match(/([\S]+)([\s]+)\+([\s]+)([\S]+)/)) { match = /([\S]+)([\s]+)\+([\s]+)([\S]+)/.exec(f); return derive(match[1], v) + " + " + derive(match[4], v); } else if (f.match(new RegExp("^([0-9]+)(" + v + ")$"))) { match = new RegExp("^([0-9]+)(" + v + ")$").exec(f); return match[1]; } else if (f.match(new RegExp("^([0-9]+)(" + v + ")\^([0-9]+)$"))) { match = new RegExp("^([0-9]+)(" + v + ")\^([0-9]+)$").exec(f); return String((match[1] * (match[3] - 1))) + v + "^" + String(match[3] - 1); } else { return "?"; } }

    Read the article

  • C# regex. Optional match after string

    - by Oskar Kjellin
    I have an input like this test1.test2.part01 which I want to strip away to test1.test2. The only thing i know is that it will end with partxx and probably a dot before the partxx. However, it will not always be a apart. Another example of input might be testas1.tlp2.asd3.part10 which ofcourse should be stripped to testas1.tlp2.asd3. I've made all that, no problem. The problem is the dot at the end before partxx. My regex at the moment is: (.*).?part\d{1,2} But it will include the dot in the group. I do not want the dot to be in the group. The below works as I want it, given that the dot exists, but it will not always be there. (.*).part\d{1,2} How can I exclude the optional dot from the group?

    Read the article

  • How can I use Boost::regex.hpp library in C++?

    - by MIH1406
    I tried to use Boost library but I failed, see my code: #include "listy.h" #include <boost/regex.hpp> using namespace boost; ListyCheck::ListyCheck() { } ListyCheck::~ListyCheck() { } bool ListyCheck::isValidItem(std::string &__item) { regex e("(\\d{4}[- ]){3}\\d{4}"); return regex_match(__item, e); } When I tried to compile it I get those messages: /usr/include/boost/regex/v4/regex_match.hpp:50: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator , std::allocator, std::allocator , boost::regex_traits ::match()' /usr/include/boost/regex/v4/basic_regex.hpp:425: undefined reference to `boost::basic_regex ::do_assign(char const*, char const*, unsigned int)' /usr/include/boost/regex/v4/perl_matcher.hpp:366: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator , std::allocator, std::allocator , boost::regex_traits ::construct_init(boost::basic_regex const&, boost::regex_constants::_match_flags)' etc...

    Read the article

  • C# Regex.IsMatch returns true when it shouldn't?

    - by James Cadd
    I'm attempting to match a string that can contain any number of numeric characters or a decimal point using the following regex: ([0-9.])* Here's some C# code to test the regex: Regex regex = new Regex("([0-9.])*"); if (!regex.IsMatch("a")) throw new Exception("No match."); I expect the exception to be thrown here but it isn't - am I using the Regex incorrectly or is there an error in the pattern? EDIT: I'd also like to match a blank string.

    Read the article

  • What does this regex mean and why

    - by Kalec
    $ sed "s/\(^[a-z,0-9]*\)\(.*\)\( [a-z,0-9]*$\)/\1\2 \1/g" desired_file_name I apreciate it even if you only explain part of it or at lest structure it with words as in s\alphanumerical_at_start\something\alphanumerical_at_end\something_else\global Could someone explain what that means, why and are all regEx so ... awful ? I know that it replaces the first lowcase alphanumerical word with the last one. But could you explain bit by bit what's going on here ? what's with all the /\ and \(.*\)\ and everything else ? I'm just lost. EDIT: Here is what I do get: (^[a-z0-9]*) starting with a trough z and 0 trough 9; and [a-z,0-9]*$ is the same but the last word (however [0-9,a-z] = just first 2 characters / first character, or the entire word ?). Also: what does the * or the \(.*\)\ even mean ?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >