473,626 Members | 3,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Matching with Parentheses

karlectomy
64 New Member
Hi all,

I am parsing text from a text file and I use Pattern and Matcher for the majority of the matching. My problem comes when I use the String.matches( String) function. Some of the lines have unclosed parentheses or unopened parentheses and These will throw the regex.PatternSy ntaxException ... some sort of exception. I have handled these but I was wondering if there was a way to ignore the parentheses or if I have to just handle the errors as they pop up?

An example of the function how I use it:
Expand|Select|Wrap|Line Numbers
  1. String tester = "ralph";
  2. String testee = "ralph)";
  3.  
  4. if(tester.matches(testee)){
  5. //Do SOmething Brilliant
  6. }
  7.  
Jan 14 '08 #1
4 3347
r035198x
13,262 MVP
Hi all,

I am parsing text from a text file and I use Pattern and Matcher for the majority of the matching. My problem comes when I use the String.matches( String) function. Some of the lines have unclosed parentheses or unopened parentheses and These will throw the regex.PatternSy ntaxException ... some sort of exception. I have handled these but I was wondering if there was a way to ignore the parentheses or if I have to just handle the errors as they pop up?

An example of the function how I use it:
Expand|Select|Wrap|Line Numbers
  1. String tester = "ralph";
  2. String testee = "ralph)";
  3.  
  4. if(tester.matches(testee)){
  5. //Do SOmething Brilliant
  6. }
  7.  
Have a look at the the specs for the String class and see if there is no methods that can achieve what you want without the fuss of regex e.g regionMatches.
Jan 14 '08 #2
BigDaddyLH
1,216 Recognized Expert Top Contributor
An example of the function how I use it:
Expand|Select|Wrap|Line Numbers
  1. String tester = "ralph";
  2. String testee = "ralph)";
  3.  
  4. if(tester.matches(testee)){
  5. //Do SOmething Brilliant
  6. }
  7.  
You need to describe your problem better. Exactly what sort of regex patterns are you using? This example looks like it could be solved by just using equals, but I'll wait for your explanation. Where are your "regex pattern strings" coming from?
Jan 14 '08 #3
karlectomy
64 New Member
Thank you for the insight. I used String.equals(S tring) instead and it seems to work just fine.
Jan 14 '08 #4
BigDaddyLH
1,216 Recognized Expert Top Contributor
Thank you for the insight. I used String.equals(S tring) instead and it seems to work just fine.
Cheers! Testing for string equality using regular expressions is overkill, to say the least.
Jan 14 '08 #5

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

Similar topics

9
4545
by: Martoni | last post by:
I need to parse a string with an embedded email address. The string always has the format NAME (name@domain) SOMETEXT. What I need to get is the email address as name@domain. I came up with this (I know it's broken, but it's a first start): <?php function ParseTicketEmail($ticket) {
6
16820
by: KathyB | last post by:
Hi, I'm passing a parameter to a script, which sometimes fails. However, I discovered that the ones failing had parentheses within the text string, e.g., "Step: Press the (0) on the console." I've learned how to escape apostrophes, but how do I do so for parens? Is it \( ? Also, where &apos; was the xml entity for apostrophe, would someone know the one for left and right parens? Can't find that either...not having much luck today...
11
3896
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...
1
3353
by: UK | last post by:
I want to extract the text within the matching parentheses. Eg Input: (S1 > 1 and S2 in ('a','b','c') and (S5 > '05/27/04' and S5 < '05/27/05') and (S4 = 'hello' or S4 = 'world') and (S_price - S_price2)) or (S1 > 1 and S3 = '12/12/03' and (S5 > 1) and (S_price - S_price2)) or (S1 > 1 and S2 in () and S3 = and (S_price - S_price2)) For the above input, my result should like below (for the 3 outer arguments) 1) S1 > 1 and S2 in...
37
2781
by: Xiao Jianfeng | last post by:
Hi, I need to print a long sting, which is two long so it must expand two lines. I know that we can use backslash(\) to explicitly join two lines into a logical line, but this doesn't work for string literals :( my code: -----------------------------------------------------------------------------
26
2374
by: John Salerno | last post by:
I probably should find an RE group to post to, but my news server at work doesn't seem to have one, so I apologize. But this is in Python anyway :) So my question is, how can find all occurrences of a pattern in a string, including overlapping matches? I figure it has something to do with look-ahead and look-behind, but I've only gotten this far: import re string = 'abababababababab'
11
3644
by: jarod1701 | last post by:
Hi, i'm currently trying to replace an unknown string using regular expressions. For example I have: user_pref("network.proxy.http", "server1") What do I have to do to replace the "server1" part (which could be
14
2916
by: nishit.gupta | last post by:
Is their any single fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" , It can also contain zero
11
4832
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?", where "*" matches zero or more consecutive occurrences of any character and "?" matches a single occurrence of any character. Does boost or some other library have this capability? If boost does have this, do i need to include an entire
0
8272
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
8205
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
8713
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
8644
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
7206
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...
1
6126
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
5579
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();...
1
2632
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
1
1817
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.