473,394 Members | 1,748 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,394 software developers and data experts.

substring and regular expression

i have read
finding sublist
http://groups.google.it/group/comp.l...56ada81fc9358a
the problem was in a string to find if we have two substring non
overlapping of lenght al least 4

it was done by
r=re.compile(r'(?P<seq>.{4,}).*(?P=seq)')

my knowhow on re is null
there is a way in re for ask if a substring is the reverse of the
otherone? First seq is second seq in reverse order

i appreciate all persons that can help me.
excuse my ignorance

Aug 4 '05 #1
4 3011
bo**********@yahoo.it wrote:
i have read
finding sublist
http://groups.google.it/group/comp.l...56ada81fc9358a
the problem was in a string to find if we have two substring non
overlapping of lenght al least 4

it was done by
r=re.compile(r'(?P<seq>.{4,}).*(?P=seq)')

my knowhow on re is null
there is a way in re for ask if a substring is the reverse of the
otherone? First seq is second seq in reverse order


For a fixed-length substring you can use brute force. Here is a regex that matches a string containing a four-character substring and its reverse:
(?P<s1>.)(?P<s2>.)(?P<s3>.)(?P<s4>.).*(?P=s4)(?P=s 3)(?P=s2)(?P=s1)

You might want to look at the Regular Expression HOW-TO document:
http://www.amk.ca/python/howto/regex/

Kent
Aug 4 '05 #2
but in general is there a way to include in a re, in this example
something like...matches iff p , and q in which p==q[::-1] ? A way to
putting a small part of code of python in re? Thanx for your many helps

Aug 4 '05 #3
borges2003xx <at> yahoo.it <borges2003xx <at> yahoo.it> writes:

but in general is there a way to include in a re, in this example
something like...matches iff p , and q in which p==q[::-1] ? A way to
putting a small part of code of python in re? Thanx for your many helps


What you are after is a parser - there are plenty available. I prefer spark, but
pyparsing has gained lots of attention lately and is AFAIK the quasi-standard.

The problem you described is a classical instance of a so-called
context-free grammar.
There is absolutely _no_ way to teach regular expressions how to detect words
created based on a grammar of that kind. Really. It won't work.

So - either use a parser, or write a simple one yourself - the code above
qualifies as an attempt to do so.

Regards,

Diez

Aug 4 '05 #4
can you be so kind to show me a small example in spark if u like for
remove all string with a substring of length 4 and the reverse of it?
i thank you a lot

Aug 6 '05 #5

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

Similar topics

2
by: Larry Woods | last post by:
I want a regular expression that will return TRUE if there is NOT a substring in the string. Example: Return true if the substring "image" is NOT in the string. TIA, Larry Woods
6
by: dreamerbin | last post by:
Hi, I'm having trouble extracting substrings using regular expression. Here is my problem: Want to find the substring that is immediately before a given substring. For example: from "00...
3
by: colinhumber | last post by:
How can I use regular expressions to search for a substring within another substring? For example, if I have the string: "This is * some text <button id="123">Some * text</button>" and I only...
5
by: btober | last post by:
I can't seem to get right the regular expression for parsing data like these four sample rows (names and addresses changed to ficticious values) from a text-type column: Yolanda Harris, 38, of...
6
by: likong | last post by:
Hi, Any idea about how to write a regular expression that matches a substring xxx as long as the string does NOT contain substring yyy? Thanks. Kong
7
by: Chris Lasher | last post by:
Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one...
7
by: Kevin CH | last post by:
Hi, I'm currently running into a confusion on regex and hopefully you guys can clear it up for me. Suppose I have a regular expression (0|(1(01*0)*1))* and two test strings: 110_1011101_ and...
8
by: Avi | last post by:
Hi all, I'm using string Replace(string oldValue, string newValue) and would like it to replace only full words that matches oldValue and not when oldValue is a substring of a larger word. ...
3
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Two part question: 1. Is Regex more efficient than manually comparing values using Substring? 2. I've never created a Regex expression. How would I use regex to do the equivalent of what 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.