User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Quick java question Page [1]  
smoothcrim
Universal Magnetic!
18966 Posts
user info
edit post

I'm trying to use java.util.regex in a program I'm writing. I want to remove a pattern off the front of strings like this
XXX*.blahblahblah => blahblahblah

My question is how do I remove the '.' ? This is what I've got so far

Pattern p = Pattern.compile("(?s)[Xx][Xx][Xx].*['.']");
Matcher m = p.matcher(str);

Any idea how to fix it?

12/1/2005 9:40:08 AM

neolithic
All American
706 Posts
user info
edit post

use a fsm

12/1/2005 9:54:45 AM

ncWOLFsu
Gottfather FTL
12586 Posts
user info
edit post

just use a substring of every string starting at the 4th character.

12/1/2005 9:56:17 AM

smoothcrim
Universal Magnetic!
18966 Posts
user info
edit post

that sort of defeats the purpose.. ie XXX45.blahblahblah would just become 5.blahblahblah.

12/1/2005 10:01:08 AM

jdlongNCSU
All American
7105 Posts
user info
edit post

does it need to be \.
?

12/1/2005 10:04:42 AM

psnarula
All American
1540 Posts
user info
edit post

yeah i think you can escape the . with \.

12/1/2005 10:19:00 AM

smoothcrim
Universal Magnetic!
18966 Posts
user info
edit post

I think it may be \\\\. gonna have to test that

12/1/2005 10:22:07 AM

drunktyper
All American
1094 Posts
user info
edit post

just string tokenize it....compare each token to the "." and once you find it, just thats where you start your substring.

12/1/2005 11:17:38 AM

ncWOLFsu
Gottfather FTL
12586 Posts
user info
edit post

oh, i definitely didnt read the question right.

if there's a variable number of characters before the '.' you can use charAt() to determine if the character at each position of the string is a '.'

once you find it, create a substring starting at the next character and go until the end of the string

12/1/2005 11:27:33 AM

smoothcrim
Universal Magnetic!
18966 Posts
user info
edit post

yeah I was trying to avoid substrings but I think I've got it both ways now. thanks

12/1/2005 11:45:55 AM

 Message Boards » Tech Talk » Quick java question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.