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

Regular expressions - pattern matching problem

12
Hi,

I am trying to match a string like this: test (AB12 A)
including the brackets.

So far, I have this code:
Expand|Select|Wrap|Line Numbers
  1. Pattern p = Pattern.compile("[A-Z]+/s+\\([A-Z]{2}[0-9]{2}/s+[A-Z]{1}\\)");
  2. Matcher m = p.matcher(string to match in here);
  3. boolean b = m.matches();
  4. if(b){
  5.   System.out.println("match seen");
  6. }else{
  7. System.out.println("Not a match");
  8. }
As you may have guessed...it doesn't work. What am I doing wrong ? Am I right with the two backslashes to match a bracket and with the /s to match a blank space ?

thanks !
Dec 19 '07 #1
5 2093
r035198x
13,262 8TB
Hi,

I am trying to match a string like this: test (AB12 A)
including the brackets.

So far, I have this code:
Expand|Select|Wrap|Line Numbers
  1. Pattern p = Pattern.compile("[A-Z]+/s+\\([A-Z]{2}[0-9]{2}/s+[A-Z]{1}\\)");
  2. Matcher m = p.matcher(string to match in here);
  3. boolean b = m.matches();
  4. if(b){
  5.   System.out.println("match seen");
  6. }else{
  7. System.out.println("Not a match");
  8. }
As you may have guessed...it doesn't work. What am I doing wrong ? Am I right with the two backslashes to match a bracket and with the /s to match a blank space ?

thanks !
Do you want to match that particular string only or do you want to match all strings with that particular structure?
Dec 19 '07 #2
basm101
12
Do you want to match that particular string only or do you want to match all strings with that particular structure?
All strings with that structure. Sorry if I didnt make myself clear

thanks
Dec 19 '07 #3
r035198x
13,262 8TB
All strings with that structure. Sorry if I didnt make myself clear

thanks
And by "that structure" you mean any two capital letters followed by two digits followed by any one capital letter and all enclosed in brackets?
Dec 19 '07 #4
basm101
12
And by "that structure" you mean any two capital letters followed by two digits followed by any one capital letter and all enclosed in brackets?
yes that is exactly what I mean
Dec 19 '07 #5
r035198x
13,262 8TB
yes that is exactly what I mean
I see now that you are also trying to match a space so there should be a space before the last character?
In that case try
Expand|Select|Wrap|Line Numbers
  1. ^\\([A-Z]{2}\\d{2}\\s[A-Z]{1}\\)$
Dec 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
11
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...
7
by: Patient Guy | last post by:
Coding patterns for regular expressions is completely unintuitive, as far as I can see. I have been trying to write script that produces an array of attribute components within an HTML element. ...
4
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...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
5
by: mikko.n | last post by:
I have recently been experimenting with GNU C library regular expression functions and noticed a problem with pattern matching. It seems to recognize only the first match but ignoring the rest of...
7
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.