Can I use regular expressions in Java 1.3
Hi,
Dose Java 1.3 suport regular expressions?
How can I use it?
Thanks.
bevin ye
The 1.3 core API doesn't support regular expressions. Hint: There's an item "Since:" in the JavaDoc of most classes that indicates the version it was initially available. If you look it up in the JavaDoc of java.util.regex.Pattern you'll notice that it's value is 1.4.
But there are several third party libraries that implement regular expressions, 'though I've not used them extensivly, so I can't tell you which one's the most usefull.
Similar Messages
-
Using regular expressions in java
Does anyone of you know a good source or a tutorial for using regular expressions in java.
I just want to look at some examples....
Thanksthanks a lot... i have one more query
Boundary matchers
^ The beginning of a line
$ The end of a line
\b A word boundary
\B A non-word boundary
\A The beginning of the input
\G The end of the previous match
\Z The end of the input but for the final terminator, if any
\z The end of the input
if i want to use the $ for comparing with string(text) then how can i use it.
Eg if it is $120 i got a hit
but if its other than that if should not hit. -
How can I use regular expression to open files of certain types in java?
Ok this is the problem I am facing:
I have a command line input of something like "/usr/foo/bar/*.html"
and there are multiple files in that folder that end with .html.
How can I use the input to go through/open all the .html files in Java?
Help would be greatly appreciated thanks!Or if you have to do it in java, check out the interfaces java.io.FileFilter and java.io.FileNameFilter
http://home.tiscali.nl/~bmc88/java/sbook/0128.html
class HTMLFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".html"));
}Cheers,
evnafets -
Using regular expressions in Java SE v1.3.1
Hi,
I have made a package in which I use the regular expressions package in J2SE v1.4. Unfortunately it turned out that my users are only using v1.3. I wonder if it is somehow possible to import the regexp package in v1.3?
Kind regards
JesperSorry No you cant use 1.4.1 RE in 1.3.1
3 ways of getting round this
1)
have 2 diff jar Files, one for 1.3.1 and one for 1.4.1
2)
use a seperate RE package
such as the Java RE package (before it was added in 1.4.1)
or apache's regexp (This is what I do) from
http://jakarta.apache.org/regexp/index.html
3)
tell your users to update to 1.4.1 !! -
How can I use regular expression to match this rule
I have a String ,value is "<a>1</a><a>2</a><a>3</a>",and want to match other String like "<a>1</a><a>8</a>",if the one of the first string(like "<a>1</a>") will occur in the second string,then will return true.but I don't know how to write the regular expresstion.
ThxFine fine. :P
I was a little bored, so here's some code that uses Strings and a StringBuffer (though you could use a String in place of the StringBuffer). Is this perhaps better? :)
String testMain = "<a>1</a><ab>2</ab><ab>3</ab>";
String test = "<ab>1</ab><ab>3</ab>";
String open = "<ab>";
String close = "</ab>";
StringBuffer search = new StringBuffer();
String checkString = null;
int lastCheck = 0;
int start = 0;
int finish = 0;
boolean done = false;
while (!done) {
start = test.indexOf(open);
finish = test.indexOf(close);
if ((start == -1) || (finish == -1)) {
System.out.println("No more tags to search for.");
done = true;
else {
checkString = test.substring((start + open.length()), finish);
search = new StringBuffer();
search.append(open);
search.append(checkString);
search.append(close);
if (testMain.indexOf(search.toString()) != -1) {
System.out.println("Found value: " + checkString);
test = test.substring(finish + close.length());
Resulting output:
Found value: 3
No more tags to search for.
-G -
Can I use regular expression in JCR QueryBuilder?
I want to find all the pages with cq:tag which end with "/testingtag"
is it possible to do so using ?
Are there any online tutorial on JCR QueryBuilder?
I tried something like that but unfortunately it is not showing what I expected to see
fulltext=testingtag$
type=cq:tagsNote that the querybuilder is a CQ (AEM) specific feature. A google search should give you what you want in the first search results: http://lmgtfy.com/?q=cq+querybuilder
Now regarding your specific question: you want to use the property predicate with the like operation:
property=cq:tags
property.value=%/testingtag
property.operation=like
However, I don't see why you would want to search for all tags ending with a certain name. Tags must always be present under /etc/tags to be valid and so the logic would always be "let the user search/select some tags, and then search for that list specifically". Use the cq tagging API (javadocs) and also the querybuilder tag predicates (which are unfortunately not so well documented):
tagid=some:tag/id
tagid.property=jcr:content/cq:tags # to set a different property path; the default is cq:tags
See also http://forums.adobe.com/message/4691188, http://forums.adobe.com/message/5223518 or https://www.sfu.ca/itservices/cms/howto/advanced/organize-and-optimize/advanced-queries.ht ml for some tagid predicate samples. -
Regular expression in java -- specifically email
Does anyone know how I can do a regular expression with java that is going to retrieve an email address pattern.
For example, let's say i have a huge string
this is a sample test. perhaps someoen can tell me how to retrieve my [email protected] from this string. sincerely yours [email protected]
could someone explain to me how to retrieve these emai addresses most efficiently using java's regular expressions
thanks
stevA citing (http://jregex.sourceforge.net/examples-email.html):
String someValidChars="[\\w.\\-]+";
String someAlphaNums="\\w+";
String dot="\\.";
Pattern email=new Pattern(someValidChars + "@" + someValidChars + dot + someAlphaNums); -
Using regular expressions for validation in i18n
Can we use regular expressions for validation of inputs in a java application taking care of i18N aspects too. Zip code for different locales are different. Can we use regular expressions to validate zipcode inputs from different locales
hi,
For that shall i have to create individual patterns for matching the inputs from different locales or a single pattern will do in the case of validating phone nos. around the world, zip codes etc. In case different patterns are required, programmer should have a konwledge of difference in patters for different locales.
regards
sdas -
How to fetch substring using regular expression
Hi,
I am new to using regular expression and would like to know some basic details of how to use them in Java.
I have a String example= "http://www.google.com/foobar.html#*q*=database&aq=f&aqi=g10&fp=c9fe100d9e542c1e" and would like to get the value of "q" parameter (in bold) using regular expression in java.
For the same example, when we tried using javascript:
match = example.match("/^http:\/\/(?:(?!mail\.)[^\.]+?\.)?google\.[^\?#]+(?:.*[\?#&](?:as_q|q)=([^&]+))?/i}");
document.write('
' + match);
We are getting the output as: http://www.google.com/foobar.html#q=database,*database* where the bold text is the value of "q" parameter.
In Java we are trying to get the value of the q parameter separately or atleast resembles the output given by JavaScript. Please help me resolving this issue.
Regards
PraveenBalusC wrote:
Regex is a cumbersome solution for fixed patterns like URL's. String#substring() in combination with String#indexOf would most likely already suffice.I usually agree, although, in this case, finding the exact parameter might be difficult without a small regex, perhaps:
"\\wq=\\s*"in conjunction with Pattern/Matcher, used similarly to an indexOf() to find the start of the parameter value.
Winston -
How to use regular expression to delete a character?
Hello,
I have a query,
select partition_name from dba_tab_partitions where table_owner='xxx'and num_rows <>0 and table_name = 'xxx';
P5
P6
P7
P12
P13
P14
P17
P18
P19
P20
P24
How can I use regular expression in above SQL query to get result without letter 'P', like..
5
6
7
12
13
14
17
18
19
20
24
thank youI find answer...
select regexp_replace(partition_name,'P','')
thanks anyway -
Getting "Inner Html" using Regular Expressions. Learning RE in SDK1.4.
Hello group.
I am learning Regular Expressions in JAVA SDK 1.4 first. Not PERL or other language.
Using the utility at the following link I am trying to get all the text between the <TR> and </TR> tags.
http://jakarta.apache.org/oro/demo.html
This seems simple but the line returns, breaks etc.. make it more difficult. I have worked on this for hours.
There will be multiple table rows in my stream.
My goal is to first get the text between the <TR> Tags...
Then I was going to use groups to get data0, data1, data2, data3.
Does this sound like a good plan? Should I use multiple RE or one RE that does 4 group returns.
I was thinking the applet was causing my problem.
<TR>.*?</TR> does not work.
(<tr>\s*([^(</tr>)])+</tr>) does not work.
I can get data0 to work as well as data1,2,3.
Would it make more sense to split this multiple row table by </tr>?
One row of malformed html (actually multiple rows):
<TR>
<TD bgColor=#ffffff><A class=fav
href="http://nicesite.com/data0"
>nicesite</A><IMG
src="smile.gif"></TD>
<TD bgColor=#12ff22><SPAN class=fav>data1</SPAN></TD>
<TD bgColor=#12ff22><SPAN class=fav>data2</SPAN></TD>
<TD bgColor=#12ff22><SPAN class=fav>data3</SPAN></TD>
<TD align=middle bgColor=#ffffff><A
href="#"><IMG
src="smile.gif" border=0></A></TD>
<TD align=middle bgColor=#ffffff>data
4</TD>
<TD align=middle bgColor=#ffffff>data5</TD></TR>
s_____ I have seen some of your post and tryed to apply them. What do you think?
Regards,
NupeVichttp://jakarta.apache.org/oro/demo.htmlI prefer
http://jregex.sourceforge.net/demoapp.html
>
This seems simple but the line returns, breaks etc..
make it more difficult. Yes, they do indeed
There will be multiple table rows in my stream.
My goal is to first get the text between the <TR>
Tags...
Then I was going to use groups to get data0, data1,
data2, data3.
Does this sound like a good plan? Should I use
multiple RE or one RE that does 4 group returns.One of the main features of regexes that you must realize
is that they are mainly suited for non-recursive, linear data structures
(btw, that's why regexes in general are hardly suited for html).
So, if the number of TD items is fixed, you could
1. search using a single pattern for the whole row, something like
"<PatternForTR>"+
"<PatternForTD>(<PatternForData>)<PatternFor/TD>"+
"<PatternForTD>(<PatternForData>)<PatternFor/TD>"+
"<PatternFor/TR>"
so the group1 would contain data1 and so on
Otherwise, you should
2. find each row using
"<PatternForTR>(.*?)<PatternFor/TR>",
then search the contents of group1 using the
"<PatternForTD>(<PatternForData>)<PatternFor/TD>".
>
<TR>.*?</TR> does not work.The pattern itself is ok, but in order for it to work one should enable the DOTALL flag (the 's' flag in jregex demo), as the '.' doesn't accept line breaks by default.
(<tr>\s*([^(</tr>)])+</tr>) does not work.It seems that [^(</tr>)]+ actually is a nonsense in this context.
It describes a string that consists of any chars but '(', ')', '<', '>', 'r', 't', '/'.
What you actully meant (a string that doesn't contain "</tr>")
is just achieved by using non-greedy quantifier in <TR>.*?</TR>.
>
I can get data0 to work as well as data1,2,3.
Would it make more sense to split this multiple row
table by </tr>?Going the second way above, you could find rows using the
general pattern for TR:
<tr.*?>(.+?)</tr> and search their contents(i.e. the group#1) using the
general pattern for TD
<td.*?>(.+?)</td> Finally, this is the specific pattern for TD that doesn't include the leading
and trailing tags into group1:
<td[^>]*>(?:\s*</?[^>]*>)*\s*(.+?)(?:\s*</?[^>]*>)*\s*</td>It succeded in finding
nicesite
data1
data2
data3
data
4
data5in your sample. -
Matching substrings between square brackets using regular expressions
Hello,
I am new at Java and have a problem with regular expressions. Let me describe the issue in 3 steps:
1.- I have an english sentence. Some words of the sentence stand between square brackets, for example "I [eat] and [sleep]"
2- I would like to match strings that are in square brackets using regular expressions (java.util.regex.*;) and here is the code I have written for the task
+Pattern findStringinSquareBrackets = Pattern.compile("\\[.*\\]");+
+ Matcher matcherOfWordInSquareBrackets = findStringinSquareBrackets.matcher("I [eat] and [sleep]");+
+//Iteration in the string+
+ while ( matcherOfWordInSquareBrackets.find() )+
+{+
+ System.out.println("Patter found! :"+ outputField.getText().substring(matcherOfWordInSquareBrackets.start(), matcherOfWordInSquareBrackets.end())+""); +
+ }+
3- the result I have after running the code described in 2 is the following: *Patter found!: [eat] and [sleep]*
That is to say that not only words between square brackets are found but also the substring "and". And this is not what I want.
What I would like to have as a result is:
*Patter found!: [eat]*
*Patter found!: [sleep]*
That is to say I want to match only the words between the square brackets and nothing else.
Does somebody know how to do this? Any help would be great.
Best regards,
AbouYou can find the words by looping through the sentence and then return the substring within the indexes.
int start=0;
int end=0;
for(int i=0; i<string.length(); i++)
if(string.substring(i,i+1).equals("[");
start=i;
if(start!=0)
if(string.substring(i,i+1).equlas("]");
end=i;
return string.substring(start,end+1);
}something like that. This code will only find the firt word however. I do not know much about regex so I cannot help anymore.
Edited by: elasolova on Jun 16, 2009 6:45 AM
Edited by: elasolova on Jun 16, 2009 6:46 AM -
Checking valid e-mail's using Regular expressions
Hey buddies ,
I desperately need some help here. I need to develop a generic method that wiull use regular expressions and patterns to validate an e-mail.
Does anyonw have any idea on how to do this. And if possible please share some code with me.
Thanks a lotYou can do regular expresions in java using java.util.regex.*:
import java.util.regex.*;
Pattern p = Pattern.compile("\\S++\\s++");
Matcher m = p.matcher(sInputLine);
if(m.find()){
sUser = m.group().trim();
}For more info on regular expressions in java, check out the javadocs:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html -
Searching for a substring using Regular Expression
I have a lengthy String similar to repetetion of the one below
String str="<option value='116813070'>Something1</option><option value='ABCDEF' selected>Something 2</option>"I need to search for the Sub string "<option value='ABCDEF' selected>" (need to get the starting index of sub string) and but the value ABCDEF can be anything numberic with varying length.
Is there any way i can do it using regular expressions(I have no other options than regular expression)?
thanks in advance.If you go through the tutorial then you will find this on the second page:
import java.io.Console;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RegexTestHarness {
public static void main(String[] args){
Console console = System.console();
if (console == null) {
System.err.println("No console.");
System.exit(1);
while (true) {
Pattern pattern =
Pattern.compile(console.readLine("%nEnter your regex: "));
Matcher matcher =
pattern.matcher(console.readLine("Enter input string to search: "));
boolean found = false;
while (matcher.find()) {
console.format("I found the text \"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(), matcher.start(), matcher.end());
found = true;
if(!found){
console.format("No match found.%n");
}It's does everything you need and a bit more. Adapt it to your needs then write a regular expression. Then if you have problems by all means come back and post them up here, but first at least attempt to solve it yourself. -
Procedure using regular expression
How to write a procedure using regular expression where i pass a string as input
The procedure should check whether it is a valid email address or not
Please help meHello,
perhaps you don't need to code it, because it's already there.
When you use the database to send your mails it or the appropriate package throws the exception
ORA-29279: Permanenter SMTP-Fehler: 501 5.5.4 Invalid Address
When you just need a procedure to check it you can write a wrapper for a java function.
import javax.mail.internet.*;
import oracle.sql.NUMBER;
public class mail_utility {
public static NUMBER validate_address(String rfc822Address) {
int rc = 0;
try {
InternetAddress ia = new InternetAddress(rfc822Address);
rc = 1;
} catch (AddressException ae) {
rc = 0;
} catch (Exception e) {
rc = -1;
} finally {
return new NUMBER(rc);
CREATE OR REPLACE FUNCTION VALIDATE_ADDRESS (p_address in varchar2)
return number
as language java name
'mail_utility.validate_address(java.lang.String) return oracle.sql.NUMBER';I think i've got it from the forum but i don't remember from whom.
Bernd
Maybe you are looking for
-
Itunes "quits unexpectedly" or crashes immediately. Please help
I recently repaired disk permissions on my macbook and now itunes won't open. It either "unexpectedly quits" or the icon in the dock just bounces until a crash report shows up. I'm wondering if anyone knows how to resolve this problem?
-
How do I create a PDF sized for the viewport of an iPhone (for iBooks)?
I tried generating PDFs from HTML, setting <meta name="viewport" content="width=320, initial-scale=2.3, user-scalable=no" /> as well as trying to set fixed widths on the elements containing text, but no matter what, the PDF shows in zoomed out view i
-
MS Office files won't open directly when double-clicked in OS 9
Hi, all. On an upgraded Lombard, I have full legal versions of both MS Office 2001 on OS 9.2.2 and Office 2004 on OS X Panther 10.3.9. Opening Office files from within OS X works fine. However, when booting into OS 9, I can't double-click to open any
-
I'm trying to burn playlists onto a cd from itunes. I keep getting a "medium write error" message. What does this mean? I heard that this may mean that I should try burning at a slower speed. I tried this and that didn't help. I also heard that
-
Nokia E-5 music player does not show all songs. Th...
my Nokia E-5 music player does not show all songs. The filemanager does though. have tried every damn thing that i could, from the internet. no solution yet. Nokia wont address it. any solutions? please dont ask me to refersh my music player. nokia n