473,787 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regular expressions

hi i am looking for pattern in regular expreesion that replaces
anything starting with and betweeen http:// until /
like http://www.start.com/startservice/yellow/ fdhttp://helo/abcd will
be replaced as
p/startservice/yellow/ fdp/abcd

Nov 6 '07 #1
3 1099
On Nov 6, 4:49 pm, krishnamanenia. ..@gmail.com wrote:
hi i am looking for pattern in regular expreesion that replaces
anything starting with and betweeen http:// until /
likehttp://www.start.com/startservice/yellow/fdhttp://helo/abcdwill
be replaced as
p/startservice/yellow/ fdp/abcd
What have you come up with so far? Have you looked at the 're' module?

--
Paul Hankin

Nov 6 '07 #2
On Tue, Nov 06, 2007 at 08:49:33AM -0800, kr************* **@gmail.com wrote regarding regular expressions:
>
hi i am looking for pattern in regular expreesion that replaces
anything starting with and betweeen http:// until /
like http://www.start.com/startservice/yellow/ fdhttp://helo/abcd will
be replaced as
p/startservice/yellow/ fdp/abcd
You don't need regular expressions to do that. Look into the methods that strings have. Look at slicing. Look at len. Keep your code readable for future generations.

Py>>help(str)
Py>>dir(str)
Py>>help(str.st artswith)

Cheers,
Cliff
Nov 6 '07 #3
On Nov 6, 11:07 am, "J. Clifford Dyer" <j...@sdf.lones tar.orgwrote:
On Tue, Nov 06, 2007 at 08:49:33AM -0800, krishnamanenia. ..@gmail.com wrote regarding regular expressions:
hi i am looking for pattern in regular expreesion that replaces
anything starting with and betweeen http:// until /
likehttp://www.start.com/startservice/yellow/fdhttp://helo/abcdwill
be replaced as
p/startservice/yellow/ fdp/abcd

You don't need regular expressions to do that. Look into the methods that strings have. Look at slicing. Look at len. Keep your code readable for future generations.

Py>>help(str)
Py>>dir(str)
Py>>help(str.st artswith)

Cheers,
Cliff
Look again at the sample input. Some of the OP's replacement targets
are not at the beginning of a word, so str.startswith wont be much
help.

Here are 2 solutions, one using re, one using pyparsing.

-- Paul
instr = """
anything starting with and betweeen "http://" until "/"
like http://www.start.com/startservice/yellow/ fdhttp://helo/abcd
will
be replaced as
"""

REPLACE_STRING = "p"

# an re solution
import re
print re.sub("http://[^/]*", REPLACE_STRING, instr)
# a pyparsing solution - with handling of target strings inside quotes
from pyparsing import SkipTo, replaceWith, quotedString

replPattern = "http://" + SkipTo("/")
replPattern.set ParseAction( replaceWith(REP LACE_STRING) )
replPattern.ign ore(quotedStrin g)

print replPattern.tra nsformString(in str)
Prints:

anything starting with and betweeen "p/"
like p/startservice/yellow/ fdp/abcd will
be replaced as
anything starting with and betweeen "http://" until "/"
like p/startservice/yellow/ fdp/abcd will
be replaced as

Nov 6 '07 #4

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

Similar topics

1
4184
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
11
3921
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being parsed can completely wreck it. The string I am trying to parse is as follows: commandText=insert into (Text) values (@message + N': ' + @category);commandType=StoredProcedure; message=@message; category=@category I am looking to retrive name value...
4
1956
by: GenoJoe | last post by:
If you are not new to VB.NET but are new to regular expressions, you need to get a free copy of "Pragmatic Guide to Regular Expressions for VB.NET Programmers". I wrote this guide because all of the sources that I researched for information on this topic, including Microsoft Help pages, did not properly address it from the viewpoint of someone new to regular expressions. If you send me an email, I will return you a zipped file that includes...
2
5100
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I have to use all the expressions seperately? Here are my regular expressions that check for valid email address and link Dim Expression As String =
2
2475
by: cleo | last post by:
I'm experimenting with Regular Expressions and Windows Forms. Frequently I want a value to be either a valid pattern or empty. For example a Zip code must be 5 digits or may be empty. I know that I can use the Regular Expression "\d{5}" to test for exactly 5 digits. How can I add the option for the string to be empty or must I always test the value before calling the Regular Expression? Thanks
4
5187
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or adate LIKE "2004.01.10 __:15") .... into something like this: .... where adate LIKE "2004.01.10 __:(30/15)" ...
3
3027
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular Expressions used in Perl identical to the Regular Expressions in PHP?
1
4387
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
10
1881
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program with a large data stream to which modules can connect using regular expressions. Now I'd like to not have to test all expressions every time I get a line, as most of the time, one of them having a match means none of the others can have so. But ofcource there are also cases where a regular expression can "contain" another expression, like in: "^strange line (\w+) and (\w+)$" and "^strange line (\w+) (?:.*?)$"...
13
7493
by: Wiseman | last post by:
I'm kind of disappointed with the re regular expressions module. In particular, the lack of support for recursion ( (?R) or (?n) ) is a major drawback to me. There are so many great things that can be accomplished with regular expressions this way, such as validating a mathematical expression or parsing a language with nested parens, quoting or expressions. Another feature I'm missing is once-only subpatterns and possessive quantifiers...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.