473,799 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular expressions - pattern matching problem

12 New Member
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 2112
r035198x
13,262 MVP
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 New Member
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 MVP
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 New Member
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 MVP
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
4187
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
3922
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...
7
2192
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. Consider the example of the HTML element TABLE with the following attributes producing sufficient complexity within the element: <table id="machines" class="noborders inred" style="margin:2em 4em;background-color:#ddd;">
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)" ...
7
3831
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
25
5174
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 (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
12
363
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 extract the name if possible from this string too: "image/4567">name</a>
3
2761
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(requestPath, "(*?\ \.ashx)"); (where requestPath is a string)
5
8786
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 them. An example: mikko.c: ----- #include <stdio.h> #include <regex.h>
7
4406
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 and stop codons on either side. This is simple enough... for example: start = AUG stop=AGG BBBBBBAUGWWWWWWAGGBBBBBB
0
9688
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
10268
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
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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...
1
4146
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
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.