Simple pattern on a string
Hi all,
I have a string, basically formatted as a URL. Sometime it refer to a poll and some times not. So I used a patter to find that a specific string directed a poll or not. Here what I have tried.
String str = "http://SimpleSite.com/poll?id=001&answer=2";
Pattern p = Pattern.compile("poll");
Matcher m = p.matcher(str.toString());
boolean b = m.matches();My code always give the result as false. Can you someone tell me how to fix this.
Thanks :)
ItsJava wrote:
You mean that my patter "poll" is not a pattern But it is a pattern but the only Strings that will match it are those that are 4 letters long and those letters are a 'p' followed by a 'o' followed by a 'l' followed by a 'l'. Your regex does not take into account any other letters before and after. I'm no regex expert but this works.
Pattern p = Pattern.compile(".*poll.*");
Similar Messages
-
How to search for a particular pattern in a string
Hi,
Hi ,
How to search for a particular pattern in a string?
I heard about java.util.regex; and used it in my jsp program.
Program I used:
<% page import="java.util.regex"%>
<% boolean b=Pattern.matches("hello world","hello");
out.println(b);%>
I run this program using netbeans and am getting the following error message.
"Cannot find the symbol : class regex"
"Cannot find the symbol : variable Pattern "
How to correct the error? -
Hi,
I want to do pattern matching using String. Here is my requirement.
String file_name = (String)hash.get("DOCNAME"));
file_name = file_name.replace("'","285745@");
So, whereever I have '(apostrophe) I will replace it with pattern "285745@" and then at another jsp where I get this request parameter I do reverse as follows:
String docname = (String)request.getParameter("doc_name").replace("285745@","'");
Now I know replace function is not going to do this. It is just a indicative, for you to know what I want to achieve. which other java function / method i can implement to get the desired result.
thanks,
ppString file_name = (String)hash.get("DOCNAME"));
file_name = file_name.replace("'","285745@");The problem here is that String.replace() operates only on char arguments, you cannot replace entire substrings with it.
The String.replaceAll() method, on the other hand, operates on regular expressions. In many common cases (those in which the substring you want to find contains no characters with special meaning to the regular expression processor) you can use it exactly as you would String.replace() except that it operates on substrings.
But regular expressions are much more powerful than that. The javadoc for the "Pattern" class has some information on how to use them. There is also a tutorial at http://java.sun.com/docs/books/tutorial/extra/regex/intro.html which you might find helpful.
In the 1.4 edition of Java there is no longer any need to screw around with while loops and StringBuffers. Nearly any text processing operation can be done with regular expressions. -
I'm trying to pattern match a string in java which has the following syntax:
ENSMUS followed by one character which can be anything followed by 11 digits.
I've done this in javascript using the following regex:
var regex = /^ENSMUS(\w{1})(\d{11})$/;I'm slightly confused by the Java equivalent (having looked at the Pattern class in the API). Could anyone lend a hand please?ENSMUS followed by one character which can be
anything followed by 11 digits.
String s = ...
boolean b = s.matches("ENSMUS.\\d{11}");Note that when matching an entire String, you don't
need to provide a beginning (^) and end ($) in your
regex. Also, you said "any character", this is not
\w, but a . (a period). \w is a "word character".So I assume if it was a word character it would be
String s = ...
boolean b = s.matches("ENSMUS\\w{1}\\d{11}");I'll try it and see what happens. Thanks -
Regex Pattern For this String ":=)"
Hello All
True, this isn't the place to ask this but here it is anyway, if you can help please do.
Can anybody tell me the regex pattern for this String:
":=)"
Thanks
JohnYep, cheers it's ":=\\)"
public class Test {
public static void main( String args[] ) {
String s = "one:=)two:=)three:=)four";
String ss[] = s.split( ":=\\)" );
for( int i=0; i<ss.length; i++ )
System.out.println( "ss["+i+"] = {" + ss[i] + "}" );
}resulting in:
ss[0] = {one}
ss[1] = {two}
ss[2] = {three}
ss[3] = {four} -
Revision: 3246
Author: [email protected]
Date: 2008-09-17 15:31:25 -0700 (Wed, 17 Sep 2008)
Log Message:
Fix fasttrack bug SDK-16910 - Simple List populated with strings throws RTE. This is fallout from the Group/DataGroup split. DefaultItemRenderer now uses a TextBox instead of a Group to show the list data.
QE: Any List tests that depended on the default item renderer to support anything other than text must be updated.
Bugs: SDK-16910
Ticket Links:
http://bugs.adobe.com/jira/browse/SDK-16910
http://bugs.adobe.com/jira/browse/SDK-16910
Modified Paths:
flex/sdk/trunk/frameworks/projects/flex4/src/flex/skin/DefaultItemRenderer.mxmlBTW, I do not experience the bug you had mentioned at
http://www.cs.rit.edu/~cxb0025/flex/TreeControlBugs.html
Can submit a video of my actions recorded -
Hi,
I need some help using pattern matching in strings .. this is what i need to do ..
if given a string of this format
String tempNotes="07/07/05 3:42 PM - 65. Java forum test 07/01/05 5:11 PM - 62. Trying regualt Expressions";I need to extract the number(s) after the time .. in the above case would be 65,62 .
The string might have more than one line of the above format .. can some one help me with this .
I tried using regular expressions .. I am pretty new to Regex's tried this
String regex="\\d(2)/\\d(2)/\\d(2)\\s\\d+:\\d(2)\\sP|AM\\s-";
Pattern p= Pattern.compile(regex);
Matcher m1 = p.matcher(tempNotes);
if(m1.find()){
System.out.println("Num = "+tempNotes.substring(m1.end()+1,m1.end()+3));
} I am totally lost .. can someone help me with this please. I need to extract all the numbers after the time .
Thanks in advance.I see two major problems with that regex. First, you're using parentheses where you should be using braces - "\\d{2}", not "\\d(2)". Second, you need to need to limit the scope of the alternation: "(?:P|A)M", or better, use a character class instead: "[PA]M". As it is, the vbar is splitting the whole regex into two alternatives. Also, you can use a capturing group to extract the number.
String regex="\\d{2}/\\d{2}/\\d{2}\\s\\d+:\\d{2}\\s[AP]M\\s-\\s+(\\d+)";
Pattern p= Pattern.compile(regex);
Matcher m1 = p.matcher(tempNotes);
while (m1.find()) {
System.out.println("Num = " + m1.group(1));
} -
Finding a pattern within a String
How can I find a pattern within a string using Java? does Java has the ability to do this or do I have to write a function?
The String API documentation shows how to do it.
-
New schema release, with pattern facet for strings?
Will Oracle release a new version of the schema processor soon, fully implementing pattern facet matches for strings? In accordance with the Last Call recommendation? Or will there be a wait while W3C puts together its release draft later this Summer?
Anybody know of any schema processors out there that validate to spec?
(XMLSPY does a good job with the Last Call spec, but only within its own framework).
Thanks.Richard,
I have just applied patch to upgrade from Portal 3.0.9 to 3.0.9.8.1 (Patch applied to loginserver and portal schema) and the External Applications that were previously set up have gone from the portlet.
Does this relate to your note at the bottom:
"Minor issues with Bulk action. 1840420 CUSTOM WRITTEN EXTERNAL AUTH MODULE NEED TO BE UPDATED AFTER 3.0.9 UPGRADE SSOXOID.PKB DOESN'T LOAD.
External authentication modules that were written before 3.0.9 need to be updated after upgrading to 3.0.9. ssoauthx.pks is updated in 3.0.9 and contains additional routines that need to be implemented." ??
If I go to the "Login Server Administration" portlet and select the link "Administer External Applications" I get a list of 5 External Applications that have previously been set up.
If I go back to the Home Page and select "customize" on the "External Applications" portlet I get the message "Your Login Server administrator has not registered any external applications".
Does that mean I should just run 'ssoauthx.pks' & 'ssoxoid.pkb' or do I need to do something else ??
Thanks
Simo -
Identifying patterns in a string & replacing all characters with 1st digit
Morning folks. Interesting problem on hand. I have a situation where I have a varchar2 text field where I have different paterns of a sequence of numbers somewhere in the string. I guess, I could write a function where by I accept the whole string and then identify one of the patters below and then finally replace only the recognized pattern with the first digit all the way through to the end of that pattern.
The catch here is that there could be free text before and after the string but there will be spaces when free text ends and the patern begins.
Here are a few patterns I would be interested in. The MAX length is 19 as in Cases 1 and 3.
1. 9999 9999 9999 9999
2. 9999999999999999
3. 9999-9999-9999-9999
4. 9999-9999-99-99999
5. 9999-999999-99999So, here would be an example of the problem in hand :
Call received on 9/22/2009.
5123-4532-8871-9876
Please follow up by 10/22/2009So, the desired output would be :
Call received on 9/22/2009.
5555-5555-5555-5555
Please follow up by 10/22/2009Any ideas ? I am stumped at the fact of before and after text in the string, hence the question for you guys !
Thanks !Here is another solution. However there has to be a better way! (I'm not a regular expression expert).
SQL> WITH test_data AS
2 (
3 SELECT 'Call received on 9/22/2009.
4 1232 3456 8765 3456
5 Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
6 SELECT 'Call received on 9/22/2009.
7 1232345687653456
8 Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
9 SELECT 'Call received on 9/22/2009.
10 1232-3456-8765-3456
11 Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
12 SELECT 'Call received on 9/22/2009.
13 1232-3456-86-3456
14 Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
15 SELECT 'Call received on 9/22/2009.
16 1232-345687-3456
17 Please follow up by 10/22/2009' AS DATA FROM DUAL
18 ), substring AS
19 (
20 SELECT DATA AS SOURCE
21 , REGEXP_INSTR
22 (
23 DATA
24 , '(([[:digit:]])+[[:space:]|-]){1,}'
25 ) AS PATSTART
26 , REGEXP_SUBSTR
27 (
28 DATA
29 , '(([[:digit:]])+[[:space:]|-]){1,}'
30 ) AS PATTERN
31 , 19 AS MAXLENGTH
32 FROM test_data
33 )
34 SELECT SUBSTR
35 (
36 SOURCE
37 , 1
38 , PATSTART-1
39 ) ||
40 TRANSLATE
41 (
42 PATTERN
43 , '0123456789'
44 , LPAD
45 (
46 SUBSTR
47 (
48 PATTERN
49 , 1
50 , 1
51 )
52 , 10
53 , SUBSTR
54 (
55 PATTERN
56 , 1
57 , 1
58 )
59 )
60 ) ||
61 SUBSTR
62 (
63 SOURCE
64 , PATSTART + MAXLENGTH
65 ) AS NEW_STRING
66 FROM substring
67 /
NEW_STRING
Call received on 9/22/2009.
1111 1111 1111 1111
Please follow up by 10/22/2009
Call received on 9/22/2009.
1111111111111111
Please follow up by 10/22/2009
Call received on 9/22/2009.
1111-1111-1111-1111
Please follow up by 10/22/2009
Call received on 9/22/2009.
1111-1111-11-1111
Please follow up by 10/22/2009
Call received on 9/22/2009.
1111-111111-1111
Please follow up by 10/22/2009
SQL> -
Match pattern for multiple strings in labVIEW
I want to include multiple strings for matching in the regular expression for pattern matching.I tried using the or option and (|)
eg:cat|dog|mouse
If the string contains any of these it should show a match.
Is it possible in labview or do i need to use multiple patch mattern functions to achieve this?Match Regular Expression function will do.
You can search for multiple strings using | operator. This function will return the match of any one of the specified strings seperated by | operator -
How to parse and isolate a pattern from a string?
Hello friends --
I am currently using the regex package to parse pathnames; i.e., active/99999999999/correspondence/file.tiff~23698, where 99999999999 is a variable 11-digit number. I have a method that is intended to not only parse but also isolate the 11-digit number and return it to the caller. The problem is that rather than return just the number, the method returns the entire string in which it is found.
Perhaps I'm going about this the wrong way. Perhaps I should convert everything to a char or byte[], and spin through each element in the array. If a digit is found, append that digit into a new array and return the new array. Sounds like it would take forever to run.
Does anyone have a clue?? A big, grateful thanks to anyone who can lend a hand.
Here is the code:
public static String locate(String subject, String find)
Pattern p = Pattern.compile(find);
Matcher m = p.matcher(subject);
String found = null;
if (m.find()) found = m.group(0);
return found;I think your code should work, if you get the pattern right.
Using pattern \d{11} with your code ("\\d{11}" as a string), I can extract the 11 digit number. But if the path contains two eleven-digit numbers, do you know for sure that you want the first one?
What pattern are you using?
HTH,
Ken -
Hi,
Can any one help me in extracting number pattern present at the end of the string in a efficient way. For eg: if i had passed priority5 to it, it should return '5'. If it is priority18, it should return 18.
Thanks in Advance
snimiIf you're talking about speed or size efficiency, it's probably not worth it unless you're doing an awful lot of these in a loop. If you're talking about programmer efficiency, you're about there.
To avoid creating a temporary string, you can do what parseInt does internally, and look at each character, convert it to a digit, and sum them, multiplying the previous sum by 10 on each step. You can also do something similar taking the hash code of the string and reverse engineering that. Neither approach tests whether the string is really of the desired format, and you'll end up writing lots of code for no real reason. -
How to get pattern from the string?
Friends,
I have 3 strings variables.
Name1,Name2 and Name 3.
I want to search following terms in above variables.
'T1' 'TURC1' 'TURC 1' and 'TURC 1X' " X=any character
'T2' 'TURC1' 'TURC 2' and 'TURC 2X' " X=any character
'T3' 'TURC1' 'TURC 3' and 'TURC 3X' " X=any character
'T4' 'TURC1' 'TURC 4' and 'TURC 4X' " X=any character
If T1 found, then v_res = 1.
If TURC1 found, then v_res = 1.
If TURC 1 found, then v_res = 1.
If TURC1X found, then v_res = 1X.
Same for 2 3 and 4.
So, How can I do this?Hi,
Try below code
Do for remaining same Strings
DATA : name1 TYPE string,
name11 TYPE string,
name2 TYPE string,
name3 TYPE string.
DATA : v_res(2) TYPE n,
w_fdpos TYPE sy-fdpos,
str TYPE i,
ch TYPE c.
name1 = 'ABCT1XRYTURC1JJTURC 1LLTURC 1A'.
str = STRLEN( name1 ).
FIND 'T1' IN name1.
IF sy-subrc = 0.
v_res = 1.
FIND 'TURC1' IN name1.
IF sy-subrc = 0.
v_res = 1.
SEARCH name1 FOR 'TURC 1'.
IF sy-subrc = 0.
v_res = 1.
w_fdpos = syst-fdpos.
w_fdpos = w_fdpos + 6.
str = str - w_fdpos.
name11 = name1+w_fdpos(str).
SEARCH name11 FOR 'TURC 1'.
IF sy-subrc = 0.
CLEAR w_fdpos.
w_fdpos = sy-fdpos.
w_fdpos = w_fdpos + 6.
ch = name11+w_fdpos(1).
CONCATENATE '1' ch INTO v_res.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
FIND 'T2' IN name1.
IF sy-subrc = 0.
v_res = 1.
FIND 'TURC2' IN name1.
IF sy-subrc = 0.
v_res = 1.
SEARCH name1 FOR 'TURC 2'.
IF sy-subrc = 0.
v_res = 1.
w_fdpos = syst-fdpos.
w_fdpos = w_fdpos + 6.
str = str - w_fdpos.
name11 = name1+w_fdpos(str).
SEARCH name11 FOR 'TURC 2'.
IF sy-subrc = 0.
CLEAR w_fdpos.
w_fdpos = sy-fdpos.
w_fdpos = w_fdpos + 6.
ch = name11+w_fdpos(1).
CONCATENATE '1' ch INTO v_res.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
FIND 'T3' IN name1.
IF sy-subrc = 0.
v_res = 1.
FIND 'TURC3' IN name1.
IF sy-subrc = 0.
v_res = 1.
SEARCH name1 FOR 'TURC 3'.
IF sy-subrc = 0.
v_res = 1.
w_fdpos = syst-fdpos.
w_fdpos = w_fdpos + 6.
str = str - w_fdpos.
name11 = name1+w_fdpos(str).
SEARCH name11 FOR 'TURC 3'.
IF sy-subrc = 0.
CLEAR w_fdpos.
w_fdpos = sy-fdpos.
w_fdpos = w_fdpos + 6.
ch = name11+w_fdpos(1).
CONCATENATE '1' ch INTO v_res.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
FIND 'T4' IN name1.
IF sy-subrc = 0.
v_res = 1.
FIND 'TURC4' IN name1.
IF sy-subrc = 0.
v_res = 1.
SEARCH name1 FOR 'TURC 4'.
IF sy-subrc = 0.
v_res = 1.
w_fdpos = syst-fdpos.
w_fdpos = w_fdpos + 6.
str = str - w_fdpos.
name11 = name1+w_fdpos(str).
SEARCH name11 FOR 'TURC 4'.
IF sy-subrc = 0.
CLEAR w_fdpos.
w_fdpos = sy-fdpos.
w_fdpos = w_fdpos + 6.
ch = name11+w_fdpos(1).
CONCATENATE '1' ch INTO v_res.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
Regards
Bala Krishna -
How to write the right pattern to replace string after a static string?
select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced ', 'CONSTANT "[A-Z0-9]' ,'CONSTANT "REPLACE') from dual;
Output is:
Do not replace CONSTANT "REPLACEAR_123" should be replaced
Proffered output is :
Do not replace CONSTANT "REPLACE" should be replaced
What is the right pattern to solve my problem?
Help is needed.
Regardsdifferent solutions possible
/* replace everthing in between "" */
select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
, '"([A-Z0-9_]*)"' ,'"REPLACE"')
from dual;
Do not replace CONSTANT "REPLACE" should be replaced
/* replace UPPER letters, Numbers and Underscore after keyword CONSTANT an in between "" */
select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
, '(CONSTANT) "([A-Z0-9_]*)"' ,'\1 "REPLACE"')
from dual;
Do not replace CONSTANT "REPLACE" should be replaced
/* replace alphanumerica values including underscore after keyword CONSTANT an in between "" */
select regexp_replace('Do not replace CONSTANT "VAR_123" should be replaced '
, '(CONSTANT) "([[:alnum:]_]*)"' ,'\1 "REPLACE"')
from dual;One problem was that you did't take into account how the underscore "_" is recognized.
Maybe you are looking for
-
How to trigger a pop-up on click of dial button on IC web UI - CRM 7.0
I want to enahcne the standard button 'Dial' that is displayed on Interaction center web UI. I am trying to show a custom popup with list of phone numbers of the BP for the sales agent to select from. I created the custom component to display the dat
-
Is it possible to create a tagged pdf with apple pages?
Not sure if possible and any tutorials would be appreciated.
-
How to incorporate Current Tax Period in Select Query.
i need to extract the data based on the Current Tax Period say current tax perios is 06-04-2007 to 05-04-2008 how to incorporate this in my select query. i need to fetch PERNR BEGDA ENDDA STAT2 FROM PA0001 INTO TABLE IT_P0001 for all entries in T_TX
-
How can Webservice manage client sections and send back messages to clients
Hi all. I am starting working with Webservice (jax-ws). Now i can make a good server side and on client side i can use method interface on webservice server side. But i want to make a advance feature as Server side manage client section and can send
-
Exporting to AOL pictures problem
Hi All, When I first downloaded aol pictures, there is an option to install a plugin to export from iphoto 08. This used to work until i purchased an hp all in one c4280 and I installed the software from the hp website. Now when I go to file->export