473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

alternatives strings syntax in regex (regular expressions)

hi,

i'm using the preg_match_all() function to parse an asp file and find
all include file within this file :

asp include strings can be :
<!--#include virtual="/dir/file.asp"-->
or
<!--#include file="/dir/file.asp"-->

then i write a really simple regex to find them :
<!--#include [virtual|file]="(.*)"-->
and it dont match any include string
i tried
<!--#include (virtual|file)="(.*)"-->
and it works, finding all include strings but returning the value
"file" or "virtual" in the first element of the $matches array
(because of parenthesis), i dont need it.

i dont know if i'm missing something but i saw this "alternative"
syntax on many exemples over the net ( [alternative1|alternative2] )

can someone light my regex quest path ?

thanks a lot
(please excuse my poor english tx)

Germain
Jul 17 '05 #1
1 2548
zOrg wrote:
....
<!--#include [virtual|file]="(.*)"-->
and it dont match any include string
square brackets "[]" specify a character class
Your regexp matches
<!--#include v="anything"-->
and
<!--#include |="someotherthing"-->
and
<!--#include e="nothing"-->
etc, etc, etc :)

i tried
<!--#include (virtual|file)="(.*)"-->
and it works, finding all include strings but returning the value
"file" or "virtual" in the first element of the $matches array
(because of parenthesis), i dont need it.
Right, "()" starts a subpattern that will be grabbed.
The file name is grabbed to the third element of the $matches array
($matches[2]).

To start a subpattern that you don't want to grab use the (?:subpattern)
syntax.
$regexp = '<!--#include (?:virtual|file)="(.*)"-->';

i dont know if i'm missing something but i saw this "alternative"
syntax on many exemples over the net ( [alternative1|alternative2] )

can someone light my regex quest path ?


check the php manual for regexps
http://www.php.net/manual/en/pcre.pattern.syntax.php
http://www.php.net/manual/en/pcre.pattern.modifiers.php

You might want to try "the regex coach"
http://www.weitz.de/regex-coach/

--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Maurice LING | last post by:
I'm trying to toy around with PLY (python lex-yacc) by David Beazley from University of Chicago and realized that the lex module uses python raw strings. What are python raw strings and how are...
4
by: Tom | last post by:
I have string that is 2.5 million bytes long. I tried using Regular Expressions to look for patterns and replace the pattern found with a pre-defined text. This works great on some computers...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
4
by: Brent | last post by:
I'd like to think that my code* is pretty simple, but I'm running into memory errors when loading larger documents. The URL you see below in the first line of the Page_Load function is about 3...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
7
by: melanieab | last post by:
Hi, I'm trying to use DataView to find the row number in the datatable that contains "Rich" in it so that I can highlight it. It works fine when I enter the entire string (i.e. Richard), but I...
1
by: Terry Olsen | last post by:
I download xml logs from several servers every day and read the data out of them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't...
5
by: Kelth.Raptor | last post by:
Im having some difficulty with strings here, I hope someone is kind enough to help, I do appreciate it. Im working on a grade point average calculator for my intro to programming class and I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.