472,969 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 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 2523
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.