Search Results

Search found 216 results on 9 pages for 'preg'.

Page 8/9 | < Previous Page | 4 5 6 7 8 9  | Next Page >

  • Easy Regex question

    - by Aaron
    Trying to replace the first 12 digits of credit card numbers with X's in a predictable blob of text that contains the string: Credit Card Number: 1234123412341234 Here's my PHP function: preg_replace('/Credit Card Number: ([0-9]{12})/','Credit Card Number: XXXXXXXXXXXX',$str); Help?

    Read the article

  • Help using preg_match for phone numbers

    - by Kirk
    how would i write an if statement that would find phone numbers and store them to a variable. Here is what i have so far but its not working. if (preg_match('/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$ /', $buffer, $matches)) { $phonenumber = html_entity_decode($matches[1]); }

    Read the article

  • what is the regular expression for this

    - by bn
    I want to parse this (adv) much (thanks) I want to eliminate the words and the bracket (adv) but not (thanks) the condition is: inside bracket, and word length inside bracket is 1-5 characters I am using preg_match in PHP Thank You

    Read the article

  • How to write a regular expression for "everything between X and Y" for use with preg_replace

    - by pg
    I want to take a variable called $encoded_str and and remove cd1, CD1 and anything between the first 'l' and the last blank space. So for example "lp6 id4 STRINGcd1" would return "STRING". I'm using PHP 4 for now so I can't use str_ireplace, I have this: $encoded_str=str_replace('CD1','',$encoded_str); $encoded_str=str_replace('cd1','',$encoded_str); $encoded_str=preg_replace('X','',$encoded_str); I've RTFM for preg_replace but am a bit confused. What should I replace the X with and can you suggest a decent introductory primer for writing regular expressions?

    Read the article

  • Substring a text since the target founded

    - by user580463
    I have a search on my php page and it is ok. With my search result, I highlighted the string target on my content. $search_tag_text = @preg_replace("/($mysearch)/i", "<u style=\"color:red\">$1</u>", $row->txtContent); Ok, but is it possible, after having found a string target on my content, to show 20 words before and 20 words after, instead listing all my content? Any help will be appreciated.

    Read the article

  • preg_match_all confusing failing

    - by James
    $string = (string) file_get_contents($_FILES['file']['tmp_name']); echo $string; preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches); print_r($matches); I am parsing text/csv files and grabbing email addresses from uploaded files. When parsing a Google Contact file I exported it weirdly fails. But when I simply copy the string that is echo'd and paste that instead of the file_get_contents result, it parses and works. Any idea why it is refusing to take the file_get_contents string, but if I paste in the raw data myself, it works?

    Read the article

  • How to get all captures of subgroup matches with preg_match_all()?

    - by hakre
    Update/Note: I think what I'm probably looking for is to get the captures of a group in PHP. Referenced: PCRE regular expressions using named pattern subroutines. (Read carefully:) I have a string that contains a variable number of segments (simplified): $subject = 'AA BB DD '; // could be 'AA BB DD CC EE ' as well I would like now to match the segments and return them via the matches array: $pattern = '/^(([a-z]+) )+$/i'; $result = preg_match_all($pattern, $subject, $matches); This will only return the last match for the capture group 2: DD. Is there a way that I can retrieve all subpattern captures (AA, BB, DD) with one regex execution? Isn't preg_match_all suitable for this? This question is a generalization. Both the $subject and $pattern are simplified. Naturally with such the general list of AA, BB, .. is much more easy to extract with other functions (e.g. explode) or with a variation of the $pattern. But I'm specifically asking how to return all of the subgroup matches with the preg_...-family of functions. For a real life case imagine you have multiple (nested) level of a variant amount of subpattern matches. Example This is an example in pseudo code to describe a bit of the background. Imagine the following: Regular definitions of tokens: CHARS := [a-z]+ PUNCT := [.,!?] WS := [ ] $subject get's tokenized based on these. The tokenization is stored inside an array of tokens (type, offset, ...). That array is then transformed into a string, containing one character per token: CHARS -> "c" PUNCT -> "p" WS -> "s" So that it's now possible to run regular expressions based on tokens (and not character classes etc.) on the token stream string index. E.g. regex: (cs)?cp to express one or more group of chars followed by a punctuation. As I now can express self-defined tokens as regex, the next step was to build the grammar. This is only an example, this is sort of ABNF style: words = word | (word space)+ word word = CHARS+ space = WS punctuation = PUNCT If I now compile the grammar for words into a (token) regex I would like to have naturally all subgroup matches of each word. words = (CHARS+) | ( (CHARS+) WS )+ (CHARS+) # words resolved to tokens words = (c+)|((c+)s)+c+ # words resolved to regex I could code until this point. Then I ran into the problem that the sub-group matches did only contain their last match. So I have the option to either create an automata for the grammar on my own (which I would like to prevent to keep the grammar expressions generic) or to somewhat make preg_match working for me somehow so I can spare that. That's basically all. Probably now it's understandable why I simplified the question. Related: pcrepattern man page Get repeated matches with preg_match_all()

    Read the article

  • Split a string by comma, quote and full-stop.. with a few exceptions

    - by dunc
    I've got a lot of text, similar to the following paragraph, which I'd like to split into words without punctuation (', ", ,, ., newline etc).. with a few exceptions. Initially considered endemic to the Chalakudy River system in Kerala state, southern India, but now recognised to have a wider distribution in surrounding drainages including the Periyar, Manimala, and Pamba river though the Manimala data may be questionable given it seems to be the type locality of P. denisonii. In the Achankovil River basin it occurs sympatrically, and sometimes syntopically, with P. denisonii. Wild stocks may have dwindled by as much as 50% in the last 15 years or so with collection for the aquarium trade largely held responsible although habitats are also being degraded by pollution from agricultural and domestic sources, plus destructive fishing methods involving explosives or organic toxins. The text refers to P. denisonii which is a species of fish. It's an abbreviation of Genus species. I would like this reference to be one word. So, for instance, this is the kind of array I'd like to see: Array ( ... [44] given [45] it [46] seems [47] to [48] be [49] the [50] type [51] locality [52] of [53] P. denisonii [54] In [55] the ... ) The only things that distinguish these species references such as P. denisonii from a new sentence like end. New are: The P (for Puntius, as in the P. in the aforementioned example) is only ever one letter, always a capital the d (as in . denisonii) is always either a lower case letter or an apostrophe (') What regexp can I use with preg_split to give me such an array? I've tried a simple explode( " ", $array ) but it doesn't do the job at all. Thanks in advance,

    Read the article

  • How do I extract specific data with preg_match?

    - by paulswansea
    I'm looking to extract values from a whole load of html (i've just trimmed down to the relevant data), there are multiple 'select' elements, and only want to extract those who's 'name' element matches the name 'aMembers'. So the resulting values I would like to retrieve are 5,10,25 and 30 (see below) how can I achieve this with preg_match? <DIV id="searchM" class="search"><select name="aMembers" id="aMembers" tabIndex="2"> <option selected="selected" value="">Data 3</option> <option value="5">A name</option> <option value="10">Another name</option> </select> </DIV> <DIV id="searchM" class="search"><select name="bMembers" id="bMembers" tabIndex="2"> <option selected="selected" value="">Data 2</option> <option value="15">A name</option> <option value="20">Another name</option> </select> </DIV> <DIV id="searchM" class="search"><select name="aMembers" id="Members" tabIndex="2"> <option selected="selected" value="">Data 1</option> <option value="25">A name</option> <option value="30">Another name</option> </select> </DIV>

    Read the article

  • How do I extract info from a block of URLs in php?

    - by Jack
    I have a list of urls, which can come in any format. One per line, separated by commas, have random text in between them, etc. the URLs are all from 2 different sites, and have a similar structure For this example, lets say it looks like this Random Text - http://www.domain2.com/variable-value Random Text 2 - http://www.domain1.com/variable-value, http://www.domain1.com/variable-value, http://www.domain1.com/variable-value http://www.domain1.com/variable-value http://www.domain2.com/variable-value http://www.domain1.com/variable-value http://www.domain2.com/variable-value http://www.domain1.com/variable-value I need to extract 2 pieces of information. Check to see if its domain1 or domain2 and the value that follows "variable-" So it should create a multi-dimensional array, which would have 2 items: domain + value. Whats the best way of doing that?

    Read the article

  • PHP preg_match, need some help

    - by SoLoGHoST
    Can someone please help me with this preg_match if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath)) // Show Error message. I need to match a possible filepath. So I need to check for double slashes, etc. Valid file path strings should look like this only: mydir/aFile.php or mydir/another_dir/anyfile.js So a slash at the beginning of this string should be checked also. Please help. Thanks :)

    Read the article

  • preg_match_all to get all occurrences of a string

    - by i5z
    I am trying to find offset of all occurrences with preg_match_all e.g. $haystack = 'aaaab'; $needle = 'aa'; preg_match_all('/' . $needle . '/', $haystack, $matches); $matches is Array ( [0] => Array ( [0] => Array ( [0] => aa [1] => 0 ) [1] => Array ( [0] => aa [1] => 2 ) ) ) It returns offset of first and second group of aa ("aa" "aa" "b") from the haystack, while I am expecting it to return "aa" starting at index 1 as well. Array ( [0] => Array ( [0] => Array ( [0] => aa [1] => 0 ) [1] => Array ( [0] => aa [1] => 1 ) [2] => Array ( [0] => aa [1] => 2 ) ) ) Is there a way I can fix the regex or use some other function (which accepts regex) to get this done? PS: I know strpos which can do this, but I have few more things to search for hence will go with preg_match_all.

    Read the article

  • Get all text between tags with preg_match_all() or better function?

    - by kylex
    2010-June-11 <remove>2010-June-2</remove> <remove>2010-June-3</remove> 2010-June-15 2010-June-16 2010-June-17 2010-June-3 2010-June-2 2010-June-1 I'm trying to find all instances that are between the <remove> tags This is what I have: $pattern = "/<remove>(.*?)<\/remove>/"; preg_match_all($pattern, $_POST['exclude'], $matches); foreach($matches as $deselect){ foreach ($deselect as $display){ echo $display."<br />"; } } This is what it returns: 2010-June-2 2010-June-3 2010-June-2 2010-June-3 Why is it doubling up, and how do I prevent that?

    Read the article

  • Replace non-html links with <A> tags

    - by tombazza
    I have a block of code that will take a block of text like the following: Sample text sample text http://www.google.com sample text Using the preg_replace_callback method and the following regular expression: preg_replace_callback('/http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)/', create_function( '$matches', '$url = $matches[1]; $anchorText = ( strlen($url) > 35 ? substr($url, 0, 35).\'...\' : $url); return \'<a href="http://\'. $url .\'">\'. $anchorText .\'</a>\';'), $str); Will convert the sample text to look like: Sample text sample text < a href="http://www.google.com"http://www.google.com< /a sample text My problem now is that we have introduced a rich text editor that can create links before being sent to the script. I need to update this piece of code so that it will ignore any URLs that are already inside an tag.

    Read the article

  • preg_replace or regex string translation

    - by ccolon
    I found some partial help but cannot seem to fully accomplish what I need. I need to be able to do the following: I need an regular expression to replace any 1 to 3 character words between two words that are longer than 3 characters with a match any expression: For example: walk to the beach == walk(.*)beach If the 1 to 3 character word is not preceded by a word that's longer than 3 characters then I want to translate that 1 to 3 letter word to ' ?' For example: on the beach == on ?the ?beach The simpler the rule the better (of course, if there's an alternative more complicated version that's more performant then I'll take that as well as I eventually anticipate heavy usage eventually). This will be used in a PHP context most likely with preg_replace. Thus, if you can put it in that context then even better!

    Read the article

  • preg_replace replacing with array

    - by Scott
    What I want to do is replace the "[replace]" in input string with the corresponding vaule in the replace array. The total number of values will change but there will always be the same number in the replace array as in input string. I have tried doing this with preg_replace and preg_replace_callback but I can't get the pattern right for [replace], I also tried using vsprintf but the % in <table width="100%"> was messing it up. All help is greatly appreciated! Replace Array: $array = array('value 1','value 2','value 3'); Input String $string = ' <table width="100%"> <tr> <td>Name:</td> <td>[replace]</td> </tr> <tr> <td>Date:</td> <td>[replace]</td> </tr> <tr> <td>Info:</td> <td>[replace]</td> </tr> </table> '; Desired Result <table width="100%"> <tr> <td>Name:</td> <td>value 1</td> </tr> <tr> <td>Date:</td> <td>value 2</td> </tr> <tr> <td>Info:</td> <td>value 3</td> </tr> </table>

    Read the article

  • Using preg_match as boolean AND array

    - by silow
    I have this code where preg_match is used to break up a string into $pmarr array. Index 1 of that array is then being used to set a value $val = $pmarr[1]. $pmarr = array(); if (preg_match($expression, $orig, $pmarr)) { $val = $pmarr[1]; } What I'm wondering about is why the preg_match itself is being used as a boolean. If the expression doesn't match, does the array stay empty and therefore equate to false? Is the above code the same as saying preg_match($expression, $orig, $pmarr); if(isset($pmarr[1]) AND !empty($pmarr[1])){ $val = $pmarr[1]; }

    Read the article

  • How can I match everything in a string until the second occurrence of a delimiter with a regular expression?

    - by Steve
    I am trying to refine a preg_match_all by finding the second occurrence of a period then a space: <?php $str = "East Winds 20 knots. Gusts to 25 knots. Waters a moderate chop. Slight chance of showers."; preg_match_all ('/(^)((.|\n)+?)(\.\s{2})/',$str, $matches); $dataarray=$matches[2]; foreach ($dataarray as $value) { echo $value; } ?> But it does not work: the {2} occurrence is incorrect. I have to use preg_match_all because I am scraping dynamic HTML. I want to capture this from the string: East Winds 20 knots. Gusts to 25 knots.

    Read the article

  • preg_match to find the current directory in a URL

    - by Ian
    I'm trying to detect the current section of a site that a user is viewing by checking for the final directory in the URL. I'm using a PHP and regex to do it and I think I'm close but unfortunately not quite there yet. Here's what I currently have: <?php $url = $_SERVER['REQUEST_URI_PATH'] = preg_replace('/\\?.*/', '', $_SERVER['REQUEST_URI']); $one = '/one/'; $two = '/three/'; $three = '/three/'; $four = '/four/'; $five = '/five/'; echo $url; if (substr($_SERVER['REQUEST_URI_PATH'], 0, strlen($one)) == $one) { // URI path starts with "/one/" echo "The section is one."; } elseif (substr($_SERVER['REQUEST_URI_PATH'], 0, strlen($two)) == $two) { // URI path starts with "/two/" echo "The section is two."; } elseif (substr($_SERVER['REQUEST_URI_PATH'], 0, strlen($three)) == $three) { // URI path starts with "/three/" echo "The section is three."; } elseif (substr($_SERVER['REQUEST_URI_PATH'], 0, strlen($four)) == $four) { // URI path starts with "/four/" echo "The section is four."; } elseif (substr($_SERVER['REQUEST_URI_PATH'], 0, strlen($five)) == $five) { // URI path starts with "/five/" echo "The section is five."; } ?> I've placed in the echo before the if statements just to get confirmation of the value of $url. This outputs /currentdirectory/file.php However the conditions themselves don't match anything and my individual echo for each section never displays. Also if there's a simpler way of doing it then I'm open to suggestions. Thanks

    Read the article

  • Matching two sections same number of times

    - by Leszczu
    Hello, i need a HTML to parse: <span>some text<span><span><span>text</span></span></span></span> I need to remove unnecessary <span> occurrences, so that output is: <span>some text<span>text</span></span> I wrote a regex, which does this once: /<SPAN>[^<]*<\/SPAN>/i How to make this work same number of times on both <span> and </span>?

    Read the article

  • Wordpress curl save Images

    - by Jeton Ramadani
    I am working on saving images from external sites into a folder in my wordpress theme. And I was wondering if its Ok to call curl twice or can it be done with one time. Example: $data = get_url('http://www.veoh.com/watch/v19935546Y8hZPgbZ'); // getting the url first curl instance preg_match('/fullHighResImagePath="(.*?)"/', $data, $thumbnail); // find the image from content savePhoto($thumbnail, $post->ID); //2nd instance of curl to save the image function get_url($url) { $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2)"; $ytc = curl_init(); // initialize curl handle curl_setopt($ytc, CURLOPT_URL, $url); // set url to post to curl_setopt($ytc, CURLOPT_FAILONERROR, 1); // Fail on errors curl_setopt($ytc, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($ytc, CURLOPT_RETURNTRANSFER, 1); // return into a variable curl_setopt($ytc, CURLOPT_PORT, 80); //Set the port number curl_setopt($ytc, CURLOPT_TIMEOUT, 15); // times out after 15s curl_setopt($ytc, CURLOPT_HEADER, 1); // include HTTP headers curl_setopt($ytc, CURLOPT_USERAGENT, $user_agent); $source = curl_exec($ytc); curl_close($ytc); $data = trim( $source ); return $data; } function savePhoto($remoteImage, $isbn) { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $remoteImage); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); $fileContents = curl_exec($ch); curl_close($ch); if (DIRECTORY_SEPARATOR=='/'){ $absolute_path = dirname(__FILE__).'/'; } else { $absolute_path = str_replace('\\', '/', dirname(__FILE__)).'/'; } $newImg = imagecreatefromstring($fileContents); return imagejpeg($newImg, $absolute_path ."video_images/{$isbn}.jpg",100); }

    Read the article

  • regular expression to read the string between <title> and </title>

    - by user262325
    Hello every one I hope to read the contents between and in a html string. I think it should be in objective-c @"<title([\\s\\S]*)</title>" below are the codes that rewrited for regular expression //source of NSStringCategory.h #import <Foundation/Foundation.h> #import <regex.h> @interface NSStringCategory:NSObject { regex_t preg; } -(id)initWithPattern:(NSString *)pattern options:(int)options; -(void)dealloc; -(BOOL)matchesString:(NSString *)string; -(NSString *)matchedSubstringOfString:(NSString *)string; -(NSArray *)capturedSubstringsOfString:(NSString *)string; +(NSStringCategory *)regexWithPattern:(NSString *)pattern options:(int)options; +(NSStringCategory *)regexWithPattern:(NSString *)pattern; +(NSString *)null; +(void)initialize; @end @interface NSString (NSStringCategory) -(BOOL)matchedByPattern:(NSString *)pattern options:(int)options; -(BOOL)matchedByPattern:(NSString *)pattern; -(NSString *)substringMatchedByPattern:(NSString *)pattern options:(int)options; -(NSString *)substringMatchedByPattern:(NSString *)pattern; -(NSArray *)substringsCapturedByPattern:(NSString *)pattern options:(int)options; -(NSArray *)substringsCapturedByPattern:(NSString *)pattern; -(NSString *)escapedPattern; @end and .m file #import "NSStringCategory.h" static NSString *nullstring=nil; @implementation NSStringCategory -(id)initWithPattern:(NSString *)pattern options:(int)options { if(self=[super init]) { int err=regcomp(&preg,[pattern UTF8String],options|REG_EXTENDED); if(err) { char errbuf[256]; regerror(err,&preg,errbuf,sizeof(errbuf)); [NSException raise:@"CSRegexException" format:@"Could not compile regex \"%@\": %s",pattern,errbuf]; } } return self; } -(void)dealloc { regfree(&preg); [super dealloc]; } -(BOOL)matchesString:(NSString *)string { if(regexec(&preg,[string UTF8String],0,NULL,0)==0) return YES; return NO; } -(NSString *)matchedSubstringOfString:(NSString *)string { const char *cstr=[string UTF8String]; regmatch_t match; if(regexec(&preg,cstr,1,&match,0)==0) { return [[[NSString alloc] initWithBytes:cstr+match.rm_so length:match.rm_eo-match.rm_so encoding:NSUTF8StringEncoding] autorelease]; } return nil; } -(NSArray *)capturedSubstringsOfString:(NSString *)string { const char *cstr=[string UTF8String]; int num=preg.re_nsub+1; regmatch_t *matches=calloc(sizeof(regmatch_t),num); if(regexec(&preg,cstr,num,matches,0)==0) { NSMutableArray *array=[NSMutableArray arrayWithCapacity:num]; int i; for(i=0;i<num;i++) { NSString *str; if(matches[i].rm_so==-1&&matches[i].rm_eo==-1) str=nullstring; else str=[[[NSString alloc] initWithBytes:cstr+matches[i].rm_so length:matches[i].rm_eo-matches[i].rm_so encoding:NSUTF8StringEncoding] autorelease]; [array addObject:str]; } free(matches); return [NSArray arrayWithArray:array]; } free(matches); return nil; } +(NSStringCategory *)regexWithPattern:(NSString *)pattern options:(int)options { return [[[NSStringCategory alloc] initWithPattern:pattern options:options] autorelease]; } +(NSStringCategory *)regexWithPattern:(NSString *)pattern { return [[[NSStringCategory alloc] initWithPattern:pattern options:0] autorelease]; } +(NSString *)null { return nullstring; } +(void)initialize { if(!nullstring) nullstring=[[NSString alloc] initWithString:@""]; } @end @implementation NSString (NSStringCategory) -(BOOL)matchedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options|REG_NOSUB]; return [re matchesString:self]; } -(BOOL)matchedByPattern:(NSString *)pattern { return [self matchedByPattern:pattern options:0]; } -(NSString *)substringMatchedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options]; return [re matchedSubstringOfString:self]; } -(NSString *)substringMatchedByPattern:(NSString *)pattern { return [self substringMatchedByPattern:pattern options:0]; } -(NSArray *)substringsCapturedByPattern:(NSString *)pattern options:(int)options { NSStringCategory *re=[NSStringCategory regexWithPattern:pattern options:options]; return [re capturedSubstringsOfString:self]; } -(NSArray *)substringsCapturedByPattern:(NSString *)pattern { return [self substringsCapturedByPattern:pattern options:0]; } -(NSString *)escapedPattern { int len=[self length]; NSMutableString *escaped=[NSMutableString stringWithCapacity:len]; for(int i=0;i<len;i++) { unichar c=[self characterAtIndex:i]; if(c=='^'||c=='.'||c=='['||c=='$'||c=='('||c==')' ||c=='|'||c=='*'||c=='+'||c=='?'||c=='{'||c=='\\') [escaped appendFormat:@"\\%C",c]; else [escaped appendFormat:@"%C",c]; } return [NSString stringWithString:escaped]; } @end I use the codes below to get the string between "" and "" NSStringCategory *a=[[NSStringCategory alloc] initWithPattern:@"<title([\s\S]*)</title>" options:0];// Unfortunately [a matchedSubstringOfString:response]] always returns nil I do not if the regular expression is wrong or any other reason. Welcome any comment Thanks interdev

    Read the article

  • Regular exp to validate email in C

    - by Liju Mathew
    Hi, We need to write a email validation program in C. We are planning to use GNU Cregex.h) regular expression. The regular expression we prepared is [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])? But the below code is failing while compiling the regex. #include <stdio.h> #include <regex.h> int main(const char *argv, int argc) { const char *reg_exp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"; int status = 1; char email[71]; regex_t preg; int rc; printf("The regex = %s\n", reg_exp); rc = regcomp(&preg, reg_exp, REG_EXTENDED|REG_NOSUB); if (rc != 0) { if (rc == REG_BADPAT || rc == REG_ECOLLATE) fprintf(stderr, "Bad Regex/Collate\n"); if (rc == REG_ECTYPE) fprintf(stderr, "Invalid Char\n"); if (rc == REG_EESCAPE) fprintf(stderr, "Trailing \\\n"); if (rc == REG_ESUBREG || rc == REG_EBRACK) fprintf(stderr, "Invalid number/[] error\n"); if (rc == REG_EPAREN || rc == REG_EBRACE) fprintf(stderr, "Paren/Bracket error\n"); if (rc == REG_BADBR || rc == REG_ERANGE) fprintf(stderr, "{} content invalid/Invalid endpoint\n"); if (rc == REG_ESPACE) fprintf(stderr, "Memory error\n"); if (rc == REG_BADRPT) fprintf(stderr, "Invalid regex\n"); fprintf(stderr, "%s: Failed to compile the regular expression:%d\n", __func__, rc); return 1; } while (status) { fgets(email, sizeof(email), stdin); status = email[0]-48; rc = regexec(&preg, email, (size_t)0, NULL, 0); if (rc == 0) { fprintf(stderr, "%s: The regular expression is a match\n", __func__); } else { fprintf(stderr, "%s: The regular expression is not a match: %d\n", __func__, rc); } } regfree(&preg); return 0; } The regex compilation is failing with the below error. The regex = [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])? Invalid regex main: Failed to compile the regular expression:13 What is the cause of this error? Whether the regex need to be modified? Thanks, Mathew Liju

    Read the article

< Previous Page | 4 5 6 7 8 9  | Next Page >