Search Results

Search found 3825 results on 153 pages for 'regex negation'.

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

  • Regex solution for Objective-C

    - by rjstelling
    What is the best method for using Regular Expressions within Objective-C? There seems to be some open source project that provide regex support, can any one recommend one? Also I looked at NSPredicate, can anyone suggest any regex examples? Background: I want use regex mainly for validation, IP's, email addresses, internal ID's etc

    Read the article

  • How to outperform this regex replacement?

    - by spender
    After considerable measurement, I have identified a hotspot in one of our windows services that I'd like to optimize. We are processing strings that may have multiple consecutive spaces in it, and we'd like to reduce to only single spaces. We use a static compiled regex for this task: private static readonly Regex regex_select_all_multiple_whitespace_chars = new Regex(@"\s+",RegexOptions.Compiled); and then use it as follows: var cleanString= regex_select_all_multiple_whitespace_chars.Replace(dirtyString.Trim(), " "); This line is being invoked several million times, and is proving to be fairly intensive. I've tried to write something better, but I'm stumped. Given the fairly modest processing requirements of the regex, surely there's something faster. Could unsafe processing with pointers speed things further?

    Read the article

  • Remove characters with regex in c#

    - by Rise_against
    Hello all, I am not a regex specialist, so I need some help with this. I have a text file, and I need to remove some trailing delimiters. The text file looks like this: MSH|^~\&|OAZIS||||20101029135359||ADT^A31|00000015|P|2.3.1||||||ASCII EVN|A31|20101029135359^^^^||||19900101 So I think the best way is to do a Regex replace? Can anyone help me with this regex? I want to remove all ^ that come before a | So test^A^^| has to become test^A| Thanks

    Read the article

  • regex to get current page or directory name?

    - by John Isaacks
    I am trying to get the page or last directory name from a url for example if the url is: http://www.example.com/dir/ i want it to return dir or if the passed url is http://www.example.com/page.php I want it to return page Notice I do not want the trailing slash or file extension. I tried this: $regex = "/.*\.(com|gov|org|net|mil|edu)/([a-z_\-]+).*/i"; $name = strtolower(preg_replace($regex,"$2",$url)); I ran this regex in PHP and it returned nothing. (however I tested the same regex in ActionScript and it worked!) So what am I doing wrong here, how do I get what I want? Thanks!!!

    Read the article

  • Zend RegEx Validator error message issue

    - by Mallika Iyer
    Hello, I'm validating a text field in my form as follows: $name = new Zend_Form_Element_Text('name'); $name->setLabel('First Name:') ->setRequired(true) ->addFilter(new Zend_Filter_StringTrim()) ->addValidator('regex',true,array('/^[(a-zA-Z0-9)]+$/')) ->addErrorMessage('Please enter a valid first name'); What I'm trying to accomplish is - how can i display a meaningful error message? Eg: If first name is 'XYZ-', how can i display '- is not allowed in first name.' Is there a way I can access what character the regex is failing for? Would you recommend something else altogether? I thought about writing a custom validator but the regex is pretty simple, so I don't see the point. I couldn't find a decent documentation for the zend 'regex' validator anywhere. If I don't override the default error message, I simple get something like : ';;;hhbhbhb' does not match against pattern '/^[(a-zA-Z0-9)]+$/' - which I obviously don't want to display to the user. I'd appreciate your inputs.

    Read the article

  • Regex For Finding Ctypes with Int32

    - by Stefan H
    (Hey all, I am looking for a little regex help... I am trying to find all CType(expression,Int32) s and replace them with CInt(expression) This, however, is proving quite difficult, considering there could be a nested Ctype(expression, Int32) within the regex match. Does anyone have any ideas for how to best go about doing this? Here is what I have now: Dim str As String = "CType((original.Width * CType((targetSize / CType(original.Height, Single)), Single)), Int32)" Dim exp As New Regex("CType\((.+), Int32\)") str = exp.Replace(str, "CInt($1)") But this will match the entire string and replace it. I was thinking of doing a recursive function to find the outer most match, and then work inwards, but that still presents a problem with things like CType(replaceChars(I), Int32)), Chr(CType(replacementChars(I), Int32) Any tips would be appreciated. Input returnString.Replace(Chr(CType(replaceChars(I), Int32)), Chr(CType(replacementChars(I), Int32))) Output: returnString.Replace(Chr(CInt(replaceChars(I))),Chr(CInt(replacementChars(I)))) Edit: Been working on it a little more and have a recursive function that I'm still working out the kinks in. Recursion + regex. it kinda hurts. Private Function FindReplaceCInts(ByVal strAs As String) As String System.Console.WriteLine(String.Format("Testing : {0}", strAs)) Dim exp As New Regex("CType\((.+), Int32\)") If exp.Match(strAs).Success Then For Each match As Match In exp.Matches(strAs) If exp.Match(match.Value.Substring(2)).Success Then Dim replaceT As String = match.Value.Substring(2) Dim Witht As String = FindReplaceCInts(match.Value.Substring(2)) System.Console.WriteLine(strAs.IndexOf(replaceT)) strAs.Replace(replaceT, Witht) End If Next strAs = exp.Replace(strAs, "CInt($1)") End If Return strAs End Function Cheers,

    Read the article

  • POSIX-compatible regex library for Visual Studio C

    - by user1397061
    I'm working on a C program which will be run in Linux and from inside Visual Studio 2010, and I'm looking for a regex library. GNU comes with a POSIX-compatible regex library, but Visual Studio, despite having C++ std::regex, doesn't have a C-compatible library. GNU has a Windows version of their library (http://gnuwin32.sourceforge.net/packages/regex.htm), but the DLLs are 32-bit only and the source code can't compile in Visual Studio (~500 errors!). My only requirement is that the end-user should not have to install anything extra, and should get the same behaviour on both platforms. I'm not picky about whether it's POSIX-style, Perl-style or something else. What should I do? Thanks in advance.

    Read the article

  • JavaScript regex - positive lookahead -- giving me syntax errors

    - by Tourshi
    This piece of regex (?<=href\=")[^]+?(?=#_) is supposed to match everything in a href value except the the hash value and what follows it within the href url. It appears to work fine under Regex debuggers/testers such as http://gskinner.com/RegExr/ but in javascript it appears to produce syntax error. If i remove the < from the (?<=) it works however, that's not the positive lookahead I am looking for. I am pulling my hair off, as usual, thanks to Regex lol Please help

    Read the article

  • Can someone suggest a way to learn regex?

    - by Nick Brooks
    In my situation knowing Regex would be very useful but I can't seem to be able to learn it. I completely don't understand it and I find it quite strange. To me Regex is just a set of jumbled up symbols which 'somehow' does the job. I looked at many tutorials and still haven't figured how to use it. The other thing I find weird that whenever I search for a way to implement something with regex I find lots of different solutions. For example these are for 'matching text between the brackets' 1: \((.*?)\) 2: ((.+?)) That confuses me even more ... Can someone suggest a good way of learning it? Personally I find it even more difficult than assembly language. For now I'm avoiding Regex and using things such as "substr" to get the bits I need.

    Read the article

  • Regex question: Why isn't this matching?

    - by AllenG
    I have the following regex: (?<=\.\d+?)0+(?=\D|$) I'm running it against a string which contains the following: SVC~NU^0270~313.3~329.18~~10~~6.00: When it runs, it matches the 6.00 (correctly) which my logic then trims by one zero to turn into 6.0. The regex then runs again (or should) but fails to pick up the 6.0. I'm by no means an expert on Regex, but my understanding of my expression is that it's looking for a decimal with 1 or more optional (so, really zero or more) digits prior to one or more zeros which are then followed by any non-digit character or the line break. Assuming that interpretation is correct, I can't see why it wouldn't match on the second pass. For that matter, I'm not sure why my Regex.Replace isn't matching the full 6.00 on the first pass and removing both of the trailing zeros... Any suggestions?

    Read the article

  • Extract string from string using Regex

    - by stacker
    I want to extract MasterPage value directive from a view page. I want the fastest way to do that, taking into account a very big aspx pages, and a very small ones. I think the best way is to do that with two stages: Extract the page directive section from the view (using Regex): <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> Then, extract the value inside MasterPageFile attribute. The result needs to be: ~/Views/Shared/Site.Master. Can I have help from someone to implement this? I badly want to use only regex, but I don't Regex expert. Another thing, Do you think that Regex is the fastest way to do this?

    Read the article

  • Need to search email body for regex using VBA

    - by user6620
    I am trying to write a script that I can run from a rule withing outlook. The goal of this script is to search the email body for a regex pattern, \d{8}-\d{3}\(E\d\) in this case. I want to take that pattern and see if a folder with the name of the match exists and if not create one. I am not super familiar with VBA as I write mostly in python. I have copied and pasted the following bit of code together but at this time I am unable to get the MsgBox to appear when I send an email with 20120812-001(E3) in the body. I have two different versions below. --version 2-- Sub Filter(Item As Outlook.MailItem) Dim Matches, Match Dim RegEx As New RegExp RegEx.IgnoreCase = True RegEx.Pattern = "\d{8}-\d{3}(E\d)" If RegEx.Test(Item.Body) Then MsgBox "Pattern Detected" End If End Sub --Version 1-- Sub ProcessMessage(myMail As Outlook.MailItem) Dim strID As String Dim objNS As Outlook.NameSpace Dim objMsg As Outlook.MailItem Dim objMatch As Match Dim RetStr As String Set objRegExp = New RegExp objRegExp.Pattern = "\d{8}-\d{3}\(E\d\)" objRegExp.IgnoreCase = True objRegExp.Global = True strID = myMail.EntryID Set objNS = Application.GetNamespace("MAPI") Set objMsg = objNS.GetItemFromID(strID) MsgBox objMsg.Body Set objMatch = objRegExp.Execute(objMsg.Body) MsgBox objMatch End Sub

    Read the article

  • java regex illegal escape character error not occurring from command line arguments

    - by Shades88
    This simple regex program import java.util.regex.*; class Regex { public static void main(String [] args) { System.out.println(args[0]); // #1 Pattern p = Pattern.compile(args[0]); // #2 Matcher m = p.matcher(args[1]); boolean b = false; while(b = m.find()) { System.out.println(m.start()+" "+m.group()); } } } invoked by java regex "\d" "sfdd1" compiles and runs fine. But if #1 is replaced by Pattern p = Pattern.compile("\d");, it gives compiler error saying illegal escape character. In #1 I also tried printing the pattern specified in the command line arguments. It prints \d, which means it is just getting replaced by \d in #2. So then why won't it throw any exception? At the end it's string argument that Pattern.compile() is taking, doesn't it detect illegal escape character then? Can someone please explain why is this behaviour?

    Read the article

  • Regex for hyperlink and hypen problem

    - by Maria
    I am trying to find links in user entered text and convert them to link automatically. I am using current Regex as following, which good to find hyperlinks from text. Regex regexResolveUrl = new Regex("((http://|www\\.)([A-Z0-9.-:]{1,})\\.[0-9A-Z?;~&#=\\-_\\./]{2,})", RegexOptions.Compiled | RegexOptions.IgnoreCase); It is working good for almost all links so far i came across but it is giving problem when i want to detect links with hypen. i.e. www.abc-xyz.com will not work, with above regex, can anyone help me with this?

    Read the article

  • Does .NET Regex support global matching?

    - by Dave
    I haven't been able to find anything online regarding this. There's RegexOptions, but it doesn't have Global as one of its options. The inline modifiers list also doesn't mention global matching. In a nutshell, I've got a regex to parse something like --arga= "arg1" --argb ="arg2" into separate argument name/value pairs using this regex: --(\\w+)\\s*=\\s*\"(\\w+)\"\\s* but the .NET Regex class doesn't do it globally (iteratively). So in order for me to get this to work, I'd have to do a match, then remove this from the argument string, and loop over and over again until I've exhausted all of the arguments. It would be nicer to run the regex once, and then loop over the match groups to get the name value pairs. Is this possible? What am I missing?

    Read the article

  • Find first item inside angular brackets after occurrence of other item, using RegEx, in C#

    - by Mihaela
    I have an xml-like text, in which I would like to find the item that occurs in the first occurrence of a certain pattern: typically: ... <PropertyGroup><name>true</name></PropertyGroup><PropertyGroup>.... .... Could also be ... <PropertyGroup> <name> true</name> </PropertyGroup> ... <PropertyGroup> ... In the above, I need to extract the "name". My initial assumption was that all occurrences were to be in one line, and I wrote my code using string properties, but it is very difficult o take in consideration every possibility, and only RegEx can save me. I just don't know how to write it... I Have started with something like this: Regex regex = new Regex("(?<=<PropertyGroup>#)<+"); Match matches = regex.Matches(Text)[0]; MessageBox.Show(matches.ToString()); I think this finds the first item after a <PropertyGroup>, but I don't know how to make it get the item within the angular brackets... (which may be after one or more newlines, and/or spaces). I know that there are utilities for parsing xml, but I am looking for something simple to insert in a c# program Can someone please help me ? Thank you very much.

    Read the article

  • Regex to exclude 1 word out of a regex code.

    - by Mech Software
    I need a regex expert to help out on this one. Examples I've found on here and the net I cant seem to get right. I'm using PHP and I have the following regex expression /([^a-zA-Z0-9])GC([A-Z0-9]+)/ This matches items like GCABCD GC123A, etc. What i need to do is EXCLUDE GCSTATS from this. So basically I want it to work just as it has, except, ignore GCSTATS in the regex.

    Read the article

  • Regex for string replace in C#

    - by Jack
    I am trying to achieve below output using regex but not able to, can someone please correct the regex - input string : data-placeholder=""[Refer" to "Conditions To Entry Of The Confirmation Order" and "Conditions To Effective Date" sections]" output string : data-placeholder="[Refer to Conditions To Entry Of The Confirmation Order and Conditions To Effective Date sections]" regex tried \s*"\s*([^ "]+)"\s*(?=["])

    Read the article

  • Some problem with regex

    - by gjoshi
    hello all in my site users can insert data using tabular format. that table can be of any style. but im using regex to give those tables a standard format of our site.but when im using regex it works well but it is removing colspan. but i need colspan widout it tables looks very odd. will anyone please tell me wats wrong with my regex?? following is my regex codes: $table=eregi_replace("<table[^>]*>","<table width='100%' border='0' cellspacing='0' cellpadding='0' class='tabularData'>", $table); $table= preg_replace('/style\s*=\s*(\'|").+(\'|")/i', '', $table); $table= preg_replace('/bgcolor\s*=\s*(\'|").+(\'|")/i', '', $table); $table=eregi_replace("<span[^>]*>","",$table); thanks in advance :)

    Read the article

  • Regex.Replace() for replacing the whole occurrence

    - by Nimmi
    Hi, Am using regex.Replace() to replace the whole occurrence of a string.. so I gave like Regex.Replace(str,@stringToReplace,"**"); where stringToReplace = @"session" + "\b"; if i give like that its not replacing.. but if i give like Regex.Replace(str,@"session\b","**"); then its working.. how to avoid this.. i want to pass value which will be set dynamically.. Thanks nimmi

    Read the article

  • regex partial match for several different groups

    - by koral
    I need regexp to match string build from several groups (A is any letter, 9 is any digit): group 1 regex [A-Z]{1,2}[0-9]? A A9 AA9 group 2 regex [A-Z]{1,3}[0-9]? A AA AAA AAA9 group 3 regex [A-Z]{2,3}[0-9]?[A-Z]? AAA AA9 AA9A group 4 regex [0-9]{1,2}[A-Z]{1,2}[0-9]? 9A 9AA 9A9 99A9 Not each group must be present but there must be all in correct order - I mean (digit is group number): 1 12 123 1234 So if there is present group 3 there must me all preceding groups present also. As there are four groups (can be more), so alternative like ^[A-Z]{1,2}[0-9]{1}|[A-Z]{1,2}[0-9]{1}\s{1}[A-Z]{1}[0-9]?$ is not the best option as it would be complicated and difficult to maintain. Is there any solution with groups or something? The order of groups is important.

    Read the article

  • (Apache) RedirectMatch regex to match all directories except those in my list

    - by dotben
    I need to 301 redirect all requests coming in for requests to http//server.com to be redirected to http//newserver.com unless the request is for an arbitary list of directories we are maintaining on the legacy server (eg server.com/foo or server.com/bar) I'm having a hard time working out how best to set this up and the regexs. EG, I need: http//server.com/page1 redirect to http//newserver.com/page1 http//server.com/dir1/page2 redirect to http//newserver.com/dir1/page2 http//server.com/foo to load as normal http//server.com/bar/baz.html to load as normal ... because 'foo' and 'bar' are in my list of legacy dirs. I'm wondering if the way to do this is to some how catch the matches in my list and then redirect anything else as a wildcard over to the new server -- but I can't make it work. Can anyone help me with some regex and rewrites for those please? Thanks (apologies for fudging the http:// in the urls, ServerFault thinks I'm posting hyperlinks and won't otherwise let me post this)

    Read the article

  • nginx regex characters that require quoting?

    - by Michael Louis Thaler
    So I was configuring nginx today and I hit a weird problem. I was trying to match a location like this: location ~ ^/([0-9]+)/(.*) { # do proxy redirects } ...for URLs like "http://my.domain.com/0001/index.html". This rule was never matching, despite the fact that it by all rights should. It took me awhile to figure out, based on this documentation, that some characters in regexes need to be quoted. The problem is, the documentation is for rewrites, and it specifically calls out curly braces, not square brackets. After a fair bit of experimentation that involved a lot of swearing, I discovered that I could fix the problem by quoting the regex like so: location ~ "^/([0-9]+)/(.*)" { # do proxy redirects } Is there a list somewhere of characters that nginx requires quoting regexes with? Or could there be something else going on here that I'm totally missing? This is my first nginx configuration job, so it's very possible I've misunderstood something...

    Read the article

  • Extract number with regex

    - by Joey
    I have this string: > HTTP/1.1 200 OK Date: Tue, 12 Nov 2013 15:26:17 GMT Server: > Apache/2.2.3 (CentOS) Last-Modified: Fri, 08 Nov 2013 21:34:50 GMT > ETag: "452//path/to/file" > Accept-Ranges: bytes Content-Length: 26010 Connection: close > Content-Type: text/plain; charset=UTF-8 And would like to extract 452 which is before // and after ETag, what regex to use? I am stuck. Thanks a lot

    Read the article

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