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
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/
-
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" -
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. -
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>"
-
Here's a very basic question about 2 TB external drives and Time Machine.
Here's a very basic question about 2 TB external drives and Time Machine.
Ihave a Mac Pro with a .75 TB and 1 TB drive. It also has a 1 TB 2ndinternal drive. My current external drive is too small so I'll begetting a 1.5 TB or 2 TB drive.
Obviouslythe new larger 2 TB drive will backup everything on the Mac Prointernal drive with Time Machine. But there will be 1 TB of space leftover going to waste.
ShouldI partition the external drive so that the TM portion will be 1 TB andthe use the remaining extra partition for additional file backups withCarbon Copy?
Thanks for any insights.
I tried searching around on the new Apple discussion forum, but I find it much harder to use than the old forum I used to use.The problem with terabyte drives is that that a 3 TB is about as big as you can get without going into RAID territory. Ideally, a Time Machine drive should be 3 times as large as all the drives you are backing up. So, if you have 2.75 TB of internal storage, you should have 8 TB of Time Machine space.
Of course, that is "should". If your TB drives are mostly empty, then you can get away with something 3 times the size of your used disk space. Just remember that you are pushing it. Linc is right about Time Machine needing space to work.
It is unlikely that you have regular churn on 2.75 TB of disk. I suggest identifying which drives and folders have the most activity and excluding those drives and directories that don't change much. It would be better to archive the data that doesn't change often and keep it out of Time Machine. Then you may be able to get away with a 2 TB Time Machine drive. -
Off Topic: Books about Regular Expression
Hi
Somebody can to indicate books about Regular Expression in Oracle ?
ThanksRegex tag of Blog of Volder.
http://volder-notes.blogspot.com/search/label/Regular%20Expressions
This entry mentions my regex solution :-)
http://volder-notes.blogspot.com/2007/10/removing-duplicate-elements-from-string.html
By the way
My regex homepage mentions regex problems of perl like regex (regex of EmEditor).
http://www.geocities.jp/oraclesqlpuzzle/regex/
example questions (written by Japanese language)
http://www.geocities.jp/oraclesqlpuzzle/regex/regex-2-1.html
http://www.geocities.jp/oraclesqlpuzzle/regex/regex-3-5.html
http://www.geocities.jp/oraclesqlpuzzle/regex/regex-4-4.html -
Basic questions about Infocube
Hi, everyone.
I got very basic questions about infocube data handling.
With infopackage, I extracted all the data about employees from R/3.
But there were some mistakes during inputting employee data, like positions,
so I just extracted those employees data once more.
Now I have two requests in infocube, where the first one has some wrong data.
Is there any solutions about this?
I might got it all wrong, so as beginner, any suggestions and explanations will
be grateful.Hi,
You can manually delete the earlier request by going in the Manage option of the cube. select the request and click on delete icon at the bottom.
Other option is to make setting in the Infopackage to delete similar or overlapping request.
Data target tab --> 6th column Automatic loading / deletion of similar request. --> click on the blank icon --> you will get a pop-up --> select the radio button - "delete existing request" --> Select Conditions --> Infosource are same, datasource are same and source system are same, --> selections are "Same or More Comprehensive "
Assign points if useful
Regards
Venkata Devaraj !!! -
Basic Questions About Compiling Source
Hi!
I have some very basic questions about compiling source on 10.6. BTW, if the unix discussions still exist, they've hidden them pretty well, so I hope I'm in the right place for this!
First off, you simply cd to the source dir, wherever it may be - in my case ~/Downloads/source/ - and during the install process, everything will be installed in its proper dir, right?
How do you know which compiler to use? There seem to be several: make, gmake, gcc, g++, etc...
Once you do figure out which compiler to run, the process is supposed to go like this, right?
./configure
make (or whatever)
make install
But this doesn't always work for me. For instance, I'm trying to compile 'arm', but it doesn't seem to have a 'configure' script.
$ ls ~/Downloads/arm
ChangeLog
README
armrc.sample
setup.py
LICENSE
arm
install
/src
Maybe it's that 'setup.py' file? What are you supposed to do?
Of course, it's not only this one that's given me trouble. Sometimes the readme will say I have to edit a certain file for my system. Are there just a few standard changes you always make? Or is it...how can I put it...complicated? How do you find out what's needed in those cases?
OS 10.6.8
Xcode 3.2.4
Python 2.7sudont wrote:
I have some very basic questions about compiling source on 10.6. BTW, if the unix discussions still exist, they've hidden them pretty well, so I hope I'm in the right place for this!
This is the place for UNIX discussions. If you have developer-related questions, there is a forum dedicated to that as well: Developer Forums
First off, you simply cd to the source dir, wherever it may be - in my case ~/Downloads/source/ - and during the install process, everything will be installed in its proper dir, right?
Yes. Hopefully the project you want to install follows standard conventions. If so, you can do "./configure", then "make", and finally "sudo make install" to install the software into "/usr/local".
How do you know which compiler to use? There seem to be several: make, gmake, gcc, g++, etc...
The make file will figure that stuff out.
Once you do figure out which compiler to run, the process is supposed to go like this, right?
./configure
make (or whatever)
make install
Yes, with the addition of "sudo" before "make install" because "/usr/local" is owned by root.
But this doesn't always work for me. For instance, I'm trying to compile 'arm', but it doesn't seem to have a 'configure' script.
$ ls ~/Downloads/arm
ChangeLog
README
armrc.sample
setup.py
LICENSE
arm
install
/src
arm? You mean "arm (anonymizing relay monitor) - Terminal status monitor for Tor relays." You really don't want to be messing with that stuff. The only people involved with Tor that are trustworthy are US Navy intelligence who have their own uses for it. If you don't understand it as well as they do, best stay away. -
Basic questions about macbook pro + external monitor
Hi,
I have some very basic questions about using a Macbook Pro + external display. I don't actually have them but need to know how things works.
So, here they are:
1) Can I use the external display as the main display?
2) Will the external display run with its resolution or with that of the mbook pro?
3) Somewhere I read that you cannot keep the macbook pro open and get the full resolution of the external display. Is that true ?
4) Is it dangerous to keep the mbook closed while using the external display?
5) Does the usage of the external display impact on mbook performance?
I know...a lot of questions , but would be nice if someone could help me.
Thanks.Hi - I am presently using an external display.
To answer your questions in sequence:
1. Yes you can use the external display as your main display. The way to enable that mode is to put your MacBook Pro to sleep, attach the external display. Wake up your MBPro with the lid closed and you will see the external display as you main display. You can alternatively set the external to "Mirror" your notebook by using preferences/display.
2. The external display will run at its resolution although you can adjust and calibrate it using Preferences/Display.
3. Not true. You get max resolution on both displays. Of course you may have to tweak as mentioned above.
4. Not at all. I use this mode all the time. Just make sure you initially set up as mentioned above and your LCD on the MBPro will stay off.
5. I have not seen any performance degradation whatsoever.
Hope this helps. -
Basic questions about CISCO IOS
Hi everybody, Jack here,
I have some basic questions about the Cisco IOS, could someone help me addressing some of them please? Any feedback would be greatly appreciated.
Basically, I have two IP addresses assigned by our Cable ISP. From what I understood you can configure a Cisco router for multiple IP addresses using the IOS, thereby allowing someone like myself to take advantage of having multiple IP addresses. This may seem unnecessary to some, but I've always wanted to put the 2nd IP address to use, since after all, I've been paying for it.
I was just wondering if someone could confirm that what I'm hoping to accomplish is indeed within the capability of the Cisco IOS (i.e. Fully utilize my 2 IP addresses). As well, if someone could kindly suggest a decent CISCO router for online gaming home use that would be super awesome!
Thank you all so much for reading through the wall of text:)
JackJack
Certainly using multiple IP addresses is in the capability of Cisco IOS routers. How they can be used depends on the relationship of the IP addresses. I am assuming that we are talking about IP addresses assigned for the user to use and that the IP address for the ISP connection is not one of these that we are talking about.
If both of the IP addresses that you have been assigned are within the same subnet then you would assign one of the addresses to the router interface to establish IP communication between the router and the ISP and to enable Internet connectivity for the devices inside your network that will use the router as their gateway to the Internet. The other address that is assigned can be used for address translation and in particular for static address translation which would make one of your devices inside to be reachable for connections initiated from the Internet (if that is something that you might want to do).
If the addresses that are assigned to you are in different subnets then you could assign one address to the outside router interface and assign the other address to the router inside interface. Or you could use the second address for address translation.
I do not have much expertise with online gaming, but I would think that either the Cisco 881 router or the 890 router might be appropriate for you. If 100 Mb connection is sufficient then probably the 881 would be the one to look at. If you need Gig connection then look at the 890.
HTH
Rick -
Basic questions about JAAS capabilities
I've never used JAAS for authentication or authorization in a Java app before. Can somebody that has (or at least has some experience and knowledge about JAAS) please answer the following couple of basic questions about it? (I know I could probably answer these myself with a few hours of reading.)
1. Can I use JAAS to restrict the users that can execute specific methods of my code?
2. If the answer to #1 is yes, is there a way to programmatically determine if a JAAS login user has the permissions to run a method before actually calling that method. In other words, can I ask something like canUserExecute(method) or do I have to just put the call to the method in a try/catch and catch a security exception of some type?
3. Is it fairly simple to have JAAS authenticate against a Windows Domain or a LDAP server?
4. Are there programmatic ways to add or edit user information in JAAS?
Answer to any of these questions are greatly appreciated. I'll even toss a couple of Dukes to the people that answer each question. Thanks in advance.You might look at the AfterthoughtSoft-Secure product at http://www.advancedmodelingconcepts.com. It is designed to do just that and will easily allow you to connect to users/group repositories that are in anything from a simple text file all the way up to Kerberos V.
You can contact the author of the product (me) at bart dot jenkins at gd-ais dot com.
bart
Maybe you are looking for
-
My Iphone has only been used for about 2 months, I have not dropped it, got it wet or anything else I can think of. I just went to reset it and it won't turn on, charge or can't be recognized on my computer. can anyone help me solve this problem?Plea
-
How could I get the Finish10 value from MS Project2010 Server_Reporting database
I am trying to get the finish10 data from project server using SQL. But it seems the finish10 column is not in MSP_EpmAssignment_Userview or MSP_EpmTask_Userview. So could you please help me to find it? Thanks.
-
Default printer in classic environment
After upgrading to 10.4.4 the default printer in Classic is changed to the default printer in OSX. If I want to print from a Classic application the first time before the print dialog is displayed I get an error message stating that apple events are
-
300 DPI images for print?
Hi All, I'd like to create a promotional leaflet for my activity, where I want to place the picture of the discounted products I'm selling. what is the minimum resolution I need to (professionally) print them? I understand that images found on the in
-
Hi - I used Flash 8 to create a Flash movie and inserted the movie using the sprite. The movie plays in Authorware but the Flash movie is missing the masking effects, colored canvas and simple graphics I included in the movie when I created it in Fla