473,407 Members | 2,315 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,407 software developers and data experts.

Regexp - matching text not containing certain count of certain characters

I'm trying to build a regular expression (POSIX extended). One part of
it has to match any text not containing a slash except standalone two
dots (..), but I can't find the way to say something like "match any
count of any characters except string ..".

For example, it should match
...anything..
aaa..
....

but must not match
anything/containing/a/slash
...

Thanks for any advice.

Jiri Fogl
Apr 9 '06 #1
4 2113
Jiri Fogl:
I'm trying to build a regular expression (POSIX extended). One part of
it has to match any text not containing a slash except standalone two
dots (..), but I can't find the way to say something like "match any
count of any characters except string ..".

For example, it should match
..anything..
aaa..
...

but must not match
anything/containing/a/slash
..


(UNTESTED)

!ereg('^\.\.$|/',$subject)

--
Jock

Apr 9 '06 #2
Thanks for advice, but this is not exactly what I need. I'll try to
explain it better:

Regular expression I need has to search through path or URL and find
every reference to a parent directory, including this parent directory.

For example if I have URL like this:
http://www.example.com/mydir/../myotherdir
RE is supposed to match /mydir/../ so I can replace it by a single slash
and get "definite" URL.

I have built a regexp to achieve this:
ereg_replace('/[^/]+/\.\./', '/', $url);

Problem of this RE appears in case of URL like this:
http://www.example.com/level1/level2..../../../target

This URL is pointing to http://www.example.com/target, but ereg_replace
above will give me
http://www.example.com/level1/level2/level3/../target. After looped
ereg_replace I get URL http://www.example.com/level1/level2/target which
is wrong.

I need to modify this part of RE: /[^/]+/
Now it says "match any string if it doesn't contain a slash" and I need
it to say "match any string if it doesn't contain a slash and it is not
..." and I need it to be a part of a RE above.

John Dunlop wrote:
Jiri Fogl:
I'm trying to build a regular expression (POSIX extended). One part of
it has to match any text not containing a slash except standalone two
dots (..), but I can't find the way to say something like "match any
count of any characters except string ..".

For example, it should match
..anything..
aaa..
...

but must not match
anything/containing/a/slash
..


(UNTESTED)

!ereg('^\.\.$|/',$subject)

Apr 9 '06 #3
Jiri Fogl:
Regular expression I need has to search through path or URL and find
every reference to a parent directory, including this parent directory.

For example if I have URL like this:
http://www.example.com/mydir/../myotherdir
RE is supposed to match /mydir/../ so I can replace it by a single slash
and get "definite" URL.


Sorry, I don't know how you'd do that with a regular expression, even
with a PCRE.

Does it need to be done with a single RE? If not, RFC3986 gives an
example algorithm for removing dot segments (sec. 5.2.4), and the whole
algorithm of section 5.2 is definitive, so I would refer to it anyway.

http://www.ietf.org/rfc/rfc3986.txt

--
Jock

Apr 11 '06 #4
John Dunlop wrote:
Jiri Fogl:
Regular expression I need has to search through path or URL and find
every reference to a parent directory, including this parent directory.

For example if I have URL like this:
http://www.example.com/mydir/../myotherdir
RE is supposed to match /mydir/../ so I can replace it by a single slash
and get "definite" URL.


Sorry, I don't know how you'd do that with a regular expression, even
with a PCRE.

Does it need to be done with a single RE? If not, RFC3986 gives an
example algorithm for removing dot segments (sec. 5.2.4), and the whole
algorithm of section 5.2 is definitive, so I would refer to it anyway.

http://www.ietf.org/rfc/rfc3986.txt


Thank you for this link very much. I didn't know about this RFC, this is
definitely what I've been searching for (even I didn't know that :-) ).

Thanks again.
Apr 18 '06 #5

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

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
3
by: Jane Doe | last post by:
Hello, I need to browse a list of hyperlinks, each followed by an author, and remove the links only for certain authors. 1. I searched the archives on Google, but didn't find how to tell the...
3
by: jasonkester | last post by:
Just a heads up for anybody that comes across this in the future. Noticed a strange behavior in RegExp.test() today. Check out the following code. It will alternately display "chokes" and null,...
1
by: Iwan Petrow | last post by:
Hi, I want to count words in a string which are NOT with length 10. For me word is a sequence of symbols different from ' '. So I want to match these words. I think that the pattern has to be...
6
by: papa.coen | last post by:
Hi, I need to split/match the following type of (singleline) syntax on all commas (or text in between) that are not between qoutes: A,'B,B',C,,'E',F The text between quotes can be _any_ text...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
9
by: =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= | last post by:
With regexps you can search for strings matching it. For example, given the regexp: "foobar\d\d\d". "foobar123" would match. I want to do the reverse, from a regexp generate all strings that could...
4
by: r | last post by:
Hello, It seems delimiters can cause trouble sometimes. Look at this : <script type="text/javascript"> function isDigit(s) { var DECIMAL = '\\.'; var exp = '/(^?0(' + DECIMAL
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.