Question in regular expressions
Hi,
I have this string (abdcerpabdcerpabdcerpaabdcerpabdcerp)
and i want to this string abdcerp and may be followed by one or more a's
So i want to get these results:
abdcerp
abdcerp
abdcerpa
abdcerp
abdcerp
I know regular expressions very well but i failed to generate one that can do so. I tried using this regex (abdcerpa*?) but it failed. it's not working and i dont know why, it's not getting abdcerpa. It only gets abdcerp
can anyone help me with that telling me the reson why did this regex is not good or tell me a regex for doing so. But I need it to be tested cause I already know about the concepts and tried different ways and regexs but failed
thanks
bye
That forum was retired and is now read-only. According to the announcement;
Any future posts on this topic should be put in the
.NET Framework Class Libraries forum.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.
Similar Messages
-
Question about Regular Expressions, please help!
I have created an app which reads files and extracts certain data using regular expressions in JDK1.4 using Pattern and Matcher classes.
However it needs to run on JDK1.2.2 (dont ask). The regular expression classes are not available in 1.2.2 (the Pattern and Matcher class) so i am looking for something similiar which i can use?
I need something that loops through all the matches found in the file like how Matcher works i.e.
while (matcher.find())
// do this
Help!http://jakarta.apache.org/regexp/
-
Basic question about regular expressions
Hello,
I am a beginner to regular expressions. I want to rewrite the following expression:
public static final String REGULAR_EXP_SOFTWARE_PART_NUMBER = "([0-9]{7}[a-z]{1})(\\-{1})([a-z]{1})";I want THIS match
(\\-{1})to occur EITHER if a hyphen is encountered OR if a space is encountered (instead of just the hyphen).
How do I rewrite this?
Thanks in advance,
Julien.Hello and thanks for your feedback,
I have created a small class as follows:
package regExpr;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
* @author Martin
public class RegExprTest {
private static String stringToBeParsed = "3800157w-e26";
public static void main(String[] args) {
Pattern pattern = Pattern.compile("" +
"([0-9]{7})" +
"([a-z]{1})" +
"(( |-){1})" +
"([a-z]{1})" +
"([0-9]{2})" +
Matcher matcher = pattern.matcher(stringToBeParsed);
while(matcher.find()){
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
System.out.println(matcher.group(3));
System.out.println(matcher.group(4));
System.out.println(matcher.group(5));
System.out.println(matcher.group(6));
}the class is trying tobreak down the following string "3800157w-e26" as follows:
3800157(seven digits)
w(one letter)
-(hyphen)
e(one letter)
26(two digits)
Oddly enough the output of the class is as follows:
3800157
w
e
26
I have to call the group method six times and I get two hyphens!
Can anyone help?
Thanks in advance,
Julien -
Simple question about regular expressions
Hi,
Using Java's regular expression syntax, what is the correct pattern string to detect strings like the following :-
AnnnnnA
where A = a single (fixed) alphabetic character and
n = at least one but possibly many digits [0-9].
Example strings to be searched :-
A45A (this should match)
A3A (this should match)
A3446655577A (this should match)
A hello world A (this should NOT match as no digits are present between the A's).
Thanks.A least one digit "A.*\\d.*A"
Only digits "A\\d+A" -
Question on regular expression.
Is there a regular expression that can exclude a set of literals?
For example, if the input string has the word 'abc' or 'xyz'
evaluating the reg expression should return false/Not Matched.
The expression
(abc)|(xyz)
will do the opposite of what I want.
Is there a way to create an expression that will produce the
opposite results of the above expression?
Thanks.Unfortunately I don't see (!) operator in the regular
expression
syntax.I believe Monica was referring to the general Java language way of negating a boolean expression. if (!str.matches(".*abc.*def.*")) {
// do stuff because this string doesn't match the regex
} Depending on your specific needs, something like that may work, or something like if (str.matches(re1) && !str.matches(re2)) { ... } Or you may want to look at negative lookahead and lookbehind. They're mentioned in the API docs, but not explained. Try googling, or check out this site:
http://www.regular-expressions.info/lookaround.html -
One question about Regular Expression!!!
I need to creat such a regular expression to match the format "[ ][ ][ ]".
For example, there is a context,
(1), " The project manager defines [1][0.400][+goals] for iterations."
Suppose that there are some spaces or "\n" characters in this way,
(2), " The project manager defines [ 1 ] [ 0.400 ]
[ +goals] for iterations."
If the pattern match the format succefully, (2) strings should be replaced by (1)strings, in order words, the format of (1) is what I need finally,
I had ever tried creating a regular expression likes \\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\] , but it does not work well!
DO YOU HOW TO IMPLEMENT IT IN JAVA?
Thanks for your any reply!What I really need is that, via the regular
expression, all the spaces and \n characters in
square brackets [ and ], ] and [, will be thrown
away.
For example,
Original:
1) "The project manager defines [ 1 ] [
0.400 ]
[ +goals] for iterations with the support"
After matching:
2) "The project manager defines [1][0.400][ [+goals]
for iterations with the support"
String 2) is what I need finally!
Thanks for your any reply!Well I gave you the answer to that one already :-)
If you need to preserve the spaces in between words use this one. I'm sure there's a better way to do it, I'm no RegEx master.
public static void main(String[] args)
String s = "[ 1 ] [ 0.400 ]\n[ +go als]";
System.out.println( "Before: " + s );
System.out.println( "\n\n" );
s = s.replaceAll( "\\[\\s+", "[" );
s = s.replaceAll( "\\s+\\]", "]" );
s = s.replaceAll( "\\]\\s+\\[", "][" );
System.out.println( "After: " + s );
} -
Beginner question about Regular expression
Hi all !
I'd like to use a regular expression to parse a string like this:
*<ID>4</ID><GROUP>5</GROUP>....*
So for example to retrieve the ID I have built the following regular expression:
Pattern p = Pattern.compile("<ID>(.*?)</ID>");
Matcher m = p.matcher(handle);
if (m.find()) {
System.out.println("->"+m.group());
} else {
System.out.println("No match!");
}The function m.group returns "<ID>4</ID>" but I want just the value (4) between the tag. Is there
a way to get it ?
thanks a lot
markfmarchioniscreen wrote:
thank you very much, that's exactly what I needed.
But it looks like you're parsing some XML like data: probably better to use a proper parser on it. Well it's a very short string containing XML tags. it's used in a marginal area of the application so I prefer just using a regular expression to fetch the values
thanks again
MarkYou could use XPath to get the value. -
Quick Question using REGULAR EXPRESSIONS
Hi Experts,
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
5 rows selected.I will be getting multiple values as input which will be separated by "[#|#]"
I need to identify and splitup values based on it and to do my process.
I have already asked similar question, but still struggling with that since the values i get in the Text is not restricted to any specific character so that not works on replacing the separator "[#|#]" by some character and using REGEXP_SUBSTR.
I need to work around some thing like below code,
DECLARE
vInfo VARCHAR2(4000) := 'cropX=42,cropY=0,Text=`$@@@@@@####[##][##][#|#]cropX=42,cropY=0,Text=`$@@@@@@####[##][##]';
vDet VARCHAR2(4000);
vPos INTEGER := 1;
LOOP
* vDet := REGEXP_SUBSTR(vInfo,'[#|#]',1,vPos); *
EXIT WHEN vDet IS NULL;
vPos := vPos+1;
-- My Process Here based on splitted values here
DBMS_OUTPUT.PUT_LINE(vDet);
END LOOP;
END; Suggest me to work out this.
Thanks,
Dharan VB'coz
Not just one value which i need to split. There are so multiple variables i need to with different separator.
Thanks for suggestion, I have STR2TBL already installed and working with that.
But not sure whether i can combine my requirement with that and to work out this ?
DECLARE
vId VARCHAR2(50) := '1,2,3';
vIdValue INTEGER;
vName VARCHAR2(40) := 'Name1,Name2,Name3';
vInfo VARCHAR2(4000) := 'cropX=42,cropY=0,Text=`$@@@@@@####[##][##][#|#]cropX=42,cropY=0,Text=`$@@@@@@####[##][##]';
vDet VARCHAR2(4000);
vPos INTEGER := 1;
BEGIN
LOOP
* vDet := REGEXP_SUBSTR(vInfo,'[#|#]',1,vPos); *
vIdValue := REGEXP_SUBSTR(vId,',',1,vPos);
EXIT WHEN vDet IS NULL;
vPos := vPos+1;
-- My Process Here based on splitted values here
DBMS_OUTPUT.PUT_LINE(vDet);
END LOOP;
END; -
An additional question about regular expressions with String.matches
does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?
It has to match the whole String. Use Matcher.find() to match on just a sub-string()
-
Simple question about regular expression
Hi
I have a little problem with
select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
answer: M
I excecute this query in SQLPlus and SQL Developer result is this same.
select regexp_substr('123 Mapla Avenue','[M]') my_test from dual;
answer: M
select regexp_substr('123 Mapla Avenue','[a]') my_test from dual;
answer: a
I used oracle 10g
Thanks for your helphm wrote:
In the oracle documentation of regexp_substr you can find:Do not confuse pattern and sort. Pattern [a-z] means any lowercase letter. REGEXP_SUBSTR parameter match_param value i tells REGEXP to treat uppercase letters same as lowercase letters and vice versa. And setting NLS_SORT can do the same. As you can see it is not that straight-forward. To make it transparent use exact pattern you need. In this particular case use:
select regexp_substr('123 Mapla Avenue','[[:alpha:]]') my_test from dual;where class [:alpha:] is POSIX predefined class of all letters (regardless of case). This way you are not dependent of client side settings like NLS_SORT and the above will always return first letter within a string. If you want first uppercase letter use:
select regexp_substr('123 Mapla Avenue','[[:upper:]]') my_test from dual;Or, for first lowercase letter:
SQL> alter session set nls_sort=binary;
Session altered.
SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
M
a
SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
M
a
SQL> alter session set nls_sort=binary_ci;
Session altered.
SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
M
M
SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
M
a
SQL> SY. -
Question about Regular Expressions
Hi averyone!
Could any one help me to create RegEx for string: <object>
Thanks!
Kind Regards, Dmitry."<object>"
-
Regular expressions in Format Definition add-on
Hello experts,
I have a question about regular expressions. I am a newbie in regular expressions and I could use some help on this one. I tried some 6 hours, but I can't get solve it myself.
Summary of my problem:
In SAP Business One (patch level 42) it is possible to use bank statement processing. A file (full of regular expressions) is to be selected, so it can match certain criteria to the bank statement file. The bank statement file consists of a certain pattern (look at the attached code snippet).
:61:071222D208,00N026
:86:P 12345678BELASTINGDIENST F8R03782497 $GH
$0000009 BETALINGSKENM. 123456789123456
0 1234567891234560
:61:071225C758,70N078
:86:0116664495 REGULA B.V. HELPMESTRAAT 243 B 5371 AM HARDCITY HARD
CITY 48772-54314
:61:071225C425,05N078
:86:0329883585 J. MANSSHOT PATTRIOTISLAND 38 1996 PT HELMEN BIJBETA
LING VOOR RELOOP RMP1 SET ORDERNR* 69866 / SPOEDIG LEVEREN
:61:071225C850,00N078
:86:0105327212 POSE TELEFOONSTRAAT 43 6448 SL S-ROTTERDAM MIJN OR
DERNR. 53846 REF. MAIL 21-02
- I am in search of the right type of regular expression that is used by the Format Definition add-on (javascript, .NET, perl, JAVA, python, etc.)
Besides that I need the regular expressions below, so the Format Definition will match the right lines from my bankfile.
- a regular expression that selects lines starting with :61: and line :86: including next lines (if available), so in fact it has to select everything from :86: till :61: again.
- a regular expression that selects the bank account number (position 5-14) from lines starting with :86:
- a regular expression that selects all other info from lines starting with :86: (and following if any), so all positions that follow after the bank account number
I am looking forward to the right solutions, I can give more info if you need any.Hello Hendri,
Q1:I am in search of the right type of regular expression that is used by the Format Definition add-on (javascript, .NET, perl, JAVA, pythonetc.)
Answer: Format Definition uses .Net regular expression.
You may refer the following examples. If necessary, I can send you a guide about how to use regular expression in Format Defnition. Thanks.
Example 6
Description:
To match a field with an optional field in front. For example, u201C:61:0711211121C216,08N051NONREFu201D or u201C:61:071121C216,08N051NONREFu201D, which comprises of a record identification u201C:61:u201D, a date in the form of YYMMDD, anther optional date MMDD, one or two characters to signify the direction of money flow, a numeric amount value and some other information. The target to be matched is the numeric amount value.
Regular expression:
(?<=:61:\d(\d)?[a-zA-Z]{1,2})((\d(,\d*)?)|(,\d))
Text:
:61:0711211121C216,08N051NONREF
Matches:
1
Tips:
1. All the fields in front of the target field are described in the look behind assertion embraced by (?<= and ). Especially, the optional field is embraced by parentheses and then a u201C?u201D (question mark). The sub expression for amount is copied from example 1. You can compose your own regular expression for such cases in the form of (?<=REGEX_FOR_FIELDS_IN_FRONT)(REGEX_FOR_TARGET_FIELD), in which REGEX_FOR_FIELDS_IN_FRONT and REGEX_FOR_TARGET_FIELD are respectively the regular expression for the fields in front and the target field. Keep the parentheses therein.
Example 7
Description:
Find all numbers in the free text description, which are possibly document identifications, e.g. for invoices
Regular expression:
(?<=\b)(?<!\.)\d+(?=\b)(?!\.)
Text:
:86:GIRO 6890316
ENERGETICA NATURA BENELU
AFRIKAWEG 14
HULST
3187-A1176
TRANSACTIEDATUM* 03-07-2007
Matches:
6
Tips:
1. The regular expression given finds all digits between word boundaries except those with a prior dot or following dot; u201C.u201D (dot) is escaped as \.
2. It may find out some inaccurate matches, like the date in text. If you want to exclude u201C-u201D (hyphen) as prior or following character, resemble the case for u201C.u201D (dot), the regular expression becomes (?<=\b)(?<!\.)(?<!-)\d+(?=\b)(?!\.)(?!-). The matches will be:
:86:GIRO 6890316
ENERGETICA NATURA BENELU
AFRIKAWEG 14
HULST
3187-A1176
TRANSACTIEDATUM* 03-07-2007
You may lose some real values like u201C3187u201D before the u201C-u201D.
Example 8
Description:
Find BP account number in 9 digits with a prior u201CPu201D or u201C0u201D in the first position of free text description
Regular expression:
(?<=^(P|0))\d
Text:
0000006681 FORTIS ASR BETALINGSCENTRUM BV
Matches:
1
Tips:
1. Use positive look behind assertion (?<=PRIOR_KEYWORD) to express the prior keyword.
2. u201C^u201D stands for that match starts from the beginning of the text. If the text includes the record identification, you may include it also in the look behind assertion. For example,
:86:0000006681 FORTIS ASR BETALINGSCENTRUM BV
The regular expression becomes
(?<=:86:(P|0))\d
Example 9
Description:
Following example 8, to find the possible BP name after BP account number, which is composed of letter, dot or space.
Regular expression:
(?<=^(P|0)\d)[a-zA-Z. ]*
Text:
0000006681 FORTIS ASR BETALINGSCENTRUM BV
Matches:
1
Tips:
1. In this case, put BP account number regular expression into the look behind assertion.
Example 10
Description:
Find the possible document identifications in a sub-record of :86: record. Sub-record is like u201C?00u201D, u201C?10u201D etc. A possible document identification sub-record is made up of the following parts:
u2022 keyword u201CREu201D, u201CRGu201D, u201CRu201D, u201CINVu201D, u201CNRu201D, u201CNOu201D, u201CRECHNu201D or u201CRECHNUNGu201D, and
u2022 an optional group made up of following:
a separator of either a dot, hyphen or slash, and
an optional space, and
an optional string starting with keyword u201CNRu201D or u201CNOu201D followed by a separator of either a dot, hyphen or slash, and
an optional space
u2022 and finally document identification in digits
Regular expression:
(?<=\?\d(RE|RG|R|INV|NR|NO|RECHN|RECHNUNG)((\.|-|/)\s?((NR|NO)(\.|-|/))?\s?)?)\d+
Kind Regards
-Yatsea -
Hi everyone,
I have a question about regular expressions.
Let's say I want my program to extract last 10-digits from any URL that will be found (every found URL will end up on 10digit number!) and insert that number in the middle of other URL.
Would anyone tell me please how to do that?
Thank youI am not sure how to do that either...
Actually I just figured out that there is no garantee that the URL will be ended on 10-digit number.
Ok, my program is meant to search for the movie info on Yahoo (user enters keyword to search and chooses either 'title', 'actor', 'trailer', 'review' in drop-down menu). After the 'search' button is clicked the appropriate page is supposed to be found.
For example, if the user types in 'shrek' and chooses 'trailer', the result is supposed to be this link http://movies.yahoo.com/movie/1808405861/trailer and not the
following ones:
http://movies.yahoo.com/mv/search?p=shrek
or
http://movies.yahoo.com/shop?d=hv&cf=info&id=1808405861
So in my program the line for the 'title' search is
url = "http://movies.yahoo.com/mv/search?type=all&p=";and it works for the titles. I thought if the found link has 10 -digit number on the end I can somehow 'catch' that number and insert into another link -so the page with trailers would be pulled up (it's an ID number in yahoo database) .
But now since I am not sure if 10-digit number is going to be in the found link at all, I have no idea how to 'catch' that number.
Does anyone have any ideas for my case? -
Regular expression to select non-matching pattern
Hi All,
I am having question on regular expressions
I want to select lines containing non-matching pattern.
For example if we consider following cities:
London
NewYork
Delhi
Mountainview
If above are the given then how to select all cities except "Delhi"
Please suggest. Thanks.Hi,
You need to explain what actually you need to get out. As all these cities are in expression [a-z, A-Z]. Some more input required.
Kuldeep Jangra -
Hi all,
I have a question regarding regular expressions.. I am refactoring a method named isPasswordValid() and removing a bunch of ugly Java code that enforces the following rules:
Does it begin with an upper or lowercase letter?
Does it contain at least one lowercase letter?
Does it contain at leasr one uppercase letter?
Does it contain at least one number?
Does it contain at least one special character from the following: !@#$%^&*-_+=
Is it at least 15 characters?I have extracted my regular expression into a dummy class for easier testing:
public class RegExTest {
public static void main(String[] args) {
String password ="qwerty34#$QWERTY";
if (password.matches("^[a-zA-Z]{1}.{14,}")
&& password.matches(".*[a-z]+.*")
&& password.matches(".*[A-Z]+.*")
&& password.matches(".*[0-9]+.*")
&& password.matches(".*[!@#$%^&*-_+=]+.*")) {
System.out.println("This is a match");
}This regular expression works as intended except for an issue with special characters. It accepts every special character specified as well as others like the tilda (~) and parenthesis. I even tried escaping the ones that needed escaping but nothing seems to work. What am I missing here? Also, do you see anything else I should be concerned with? Of course, any help would be greatly appreciated!
Thanks!When not placed at the start or end of a character class, the hyphen is a range operator:
[a-d] // matches 'a', 'b', 'c' or 'd'
[ad-] // matches 'a', 'd' or '-'
[-ad] // matches '-', 'a' or 'd'Or escape it:
[a\-d] // matches 'a', '-' or 'd'
Maybe you are looking for
-
How many movies can you rent on an apple tv at any one time
just trying to find out 1. how many movies you can rent and store via apple tcv at any one time 2. when you rent a movie through apple tv where does it get stored or downloaded to
-
I have updated my iPhone 4s to iOS7 but when i connect it to itunes on my PC it give me a msg to restore your iPhone in summary tab, Please help m using win 7 and updated itunes.
-
Soft to modify fsb of KT6V under windows ?
I am looking for a soft to modify fsb of KT6V. CPUCool doesn't work with the PLL Winbond 83697. Otherwise is it available a bios mod to change cpu ratio by bios with a XP-M unlocked (easily to change this under windows with CPUMSR) ?
-
Can i use mac mail in windows. from where can i download it
Hi Apple, I would like to use mail.app (Mac mail client) in windows. Could you people please help me out in this. from where i can download this for windows. Thanks, Anand
-
Custom speed not working in motion path behaviour of emitter
I am trying ot make a custom speed motion path along an open spline. Any amount of adjusting of keyframes and percentages produce no movement at all along the path. The emitter is stuck at the beginning of the path. All the other speed options work e