Question on regex Matcher (group number)
HI, everybody
I am writing a program on replacement like the one below.
String regex = "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)";
String original = "ABCDEFGHIJKL";
String replacement = "$12";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(original);
String result = m.replaceFirst(replacement);What I actually want is to take out the first group, in this case an "A", and append a character "2" after it.
The result I am expecting is "A2". But the result I get is "L". For the regex engine takes it as the 12th group.
What should I do to remove the ambiguity.
Thanks.
In such case, use $1\\2.
Similar Messages
-
Regex multiple groups matching question
Hi,
I have three types of inputs: A,B,C
I need to match sequences of:
AAA...ABC
If I truncate the input to contain only A's, and use a Matcher that searchs for A, I can read all A's instances with matcher's group methods.
If I apply the whole sequence to the full regex, I can only read the last A (B and C too).
How can I get the "subgroups" of A's?
Do I need to split up the input and use two regex's? Is there a way to make the matcher assign a different group for each A, and one group for each B and C? So I can iterate over the groups?
regex I use:
(A)+?(B)(C) (reluctant modifier)
ThanksA, B and C are not characters, they are expressions.
I would like to be able to read all groups of A when I apply my regex to the whole sequence.
Here is my code, in case it is needed. Some examples of valid inputs I need to read:
5.0x + 10y = 20
-2t1 +3.5t3 >= 0.5
etc
import java.util.regex.*;
public class ModelParser {
private static final String factor = "(?:([+-]?)\\s*(\\d+(?:\\.\\d)?))";
private static final String variable = "(?:\\s*(\\w+))";
private static final String expression = "(?:" + factor + variable + "\\s*)+?";
private static final String operand = "(=|>=|<=)";
private static final String regex =
//expression;
expression + operand + factor;
public ModelParser(String input) {
System.out.println(input);
System.out.println(regex);
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
boolean matches;
while (matches = m.find()) {
System.out.println("Groups: " + m.groupCount());
int groups = m.groupCount();
for (int i = 0; i <= groups; ++i) {
System.out.println("Group " + i + ": " + m.group(i) +
" from: " + m.start(i) + " to " + m.end(i));
public static void main(String[] args) {
ModelParser mp = new ModelParser(" + 3.5y - 2.0x = 5");
//ModelParser mp = new ModelParser(" + 3.5y - 2.0x");
}You can use the commented lines (regex and input at the main method) instead and check that it is reading ok the "A" groups. -
Capture regex match as a variable?
Hello!
I have this program and I basically want to match a part of a string and grab the match as a variable. In this case, the string I need to parse is 'foo'.
Here is what I have:
public class Test
public static void main(String[] args)
// link <link> format
String foo = "http://www.foo.com <http://www.foo.com>";
String the_regex = "\\<(http://[^\\>]*)\\>";
String the_replacement = "<a href=\"$1\">$1</a>";
System.out.println(foo.replaceAll(the_regex,the_replacement));
}$1 (sorta like PERL) should be the captured text from the_regex
Any ideas?
Thanks in advance.Dubwai - I think I got it, thanks for the guidance. Here is what I used, and it seems to work. Thanks!
public class Test
public static void main(String[] args)
String foo = "http://www.foo.com <http://www.boo.com>";
String regex="\\<(http://[^\\>]*)\\>";
Pattern p = Pattern.compile(regex);
Matcher m1 = p.matcher(foo);
while (m1.find())
System.out.println("The site = " + m1.group(1));
} -
Regex capture groups in IdocScript
Hello,
I'm looking for a way to print out capture groups as part of a regex match using Idoc Script. Here's a basic example of what I'm trying to do.
HTML:
<p>This is a paragraph of text</p>
Idoc Script:
<!--$r = wcmElement("regexText")-->
<!--$if regexMatches(regexText, "<p>(.*)</p>")-->
<!--$firstParagraph = $1-->
<!--$endif-->
Essentially, what I'm trying to do is store the value between the <p></p> tags in a variable. I know there's a syntax error in my above script, but the IdocScript documentation does not touch on capture groups at all, so I'm left to guess on what I know from other scripting languages.
Thanks,
Josh<p> tags are escaped and ssIncludeXML will not do the trick.
you can try somethign like..
<!--$myHTMlMarkup =wcmElement("regexText")-->
<!--$startindex= strIndexOf(myHTMlMarkup,">p<")-->
<$loopwhile startindex+ 1 > 0$>
<!--$stopIndex= strIndexOf(myHTMlMarkup,">/p<")-->
<!--$para = strSubstring(myHTMlMarkup,startindex + 9,stopIndex) -->
<!--$myHTMlMarkup=strIndexOf(myHTMlMarkup,stopIndex + 10)-->
<!--$startindex= strIndexOf(myHTMlMarkup,">p<")-->
<!--$endloop--> -
Hi,
I want to display group number in the footer of group in SSRS(this task needs to be done in report but not in sql).How can we accomlish this.
Ex:If report is grouped by state
PA(GroupHeader)
Detail row
GroupFooter(1)
NJ(GroupHeader)
Detail row
GroupFooter(2)
i.e for PA group in footer it should display 1.
for 2 nd group display 2 and so on.qHi,
Modify the code as below,
shared dim Categories as new collection
shared Counter as integer=0
public function getGroupCounter(Item as String) as String
if Categories.contains(Item) then return "Group Footer " & Categories(Item).tostring()
Counter=Counter+1
Categories.add(Counter,Item)
return "Group Footer " & Counter.tostring()
end function
Then modify the expression that calls the code. You have to pass parameter that makes it unique througout your report. You may need to concatenate all the values of the group levels from 7 to 2 to achieve this like shown below.
=Code.getGroupCounter(Fields!Field1.Value & Fields!Field2.Value & Fields!Field3.Value)
Replace Field1, Field2 etc with the Field names you used in the group by while creating the groups.
Please feel free to discuss any further questions.
Regards
Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH -
Regex: named group capturing?
Hi, I know that in JAVA regular expression "capturing groups are numbered by counting their opening parentheses from left to right", but is there anyway to assign a name to a capturing group, like the way in python:
(?P<year>[0-9][0-9][0-9][0-9]) //see regular expression Howto website
where this group is named "year" and and be retrieved by the group name.
Can I do this in JAVA regex? Any hints please, thanks!I made some changes to sun's regExps to support named groups.
http://gorbush.narod.ru/files/regex2.zip
String
"TEST 123"
RegExp
"(?<login>\\w+) (?<id>\\d+)"
Access
matcher.group(1) = TEST
matcher.group("login") = TEST
matcher.name(1) = login
Replace
matcher.replaceAll("aaaaa_$1_sssss_$2____") = aaaaa_TEST_sssss_123____
matcher.replaceAll("aaaaa_${login}_sssss_${id}____") = aaaaa_TEST_sssss_123____ -
How d you creat group number on n 95-1
When defining transfers to nonlocal numbers, it is important to note that transfer-pattern digit matching is performed before translation-rule operations. Therefore, you should specify in this command the digits that are actually entered by phone users before they are translated.
Router(config-telephony)# transfer-pattern XXXX
http://www.cisco.com/en/US/products/sw/voicesw/ps4625/products_configuration_guide_chapter09186a00804ad864.html
http://www.cisco.com/en/US/products/sw/voicesw/ps4625/products_configuration_guide_chapter09186a00804ad858.html -
How can I set up an SMS group so that all group members can dial a group number and have a text sent out to all members of the group
This would be an SMS group similar to an email listserv but running on the SMS network
I have seen private individuals offering this service
It seems strange to me that no internet site like Apple, Yahoo or Google offers this as a free service much as the email group services are free services.
SteveI think the app GroupMe might do what you want. You might also try contacting your carrier. My carrier offered some fancy group texting service for a while but they never really advertised it so, unless you asked, you never would have known. But, GroupMe is available in the app store. There are lots of other apps that also do group texting but it seems to be the one that gets recommended the most.
-
How do i delete an old iCloud account from phone when I forget my password and I'm not able to reset it because my security questions do not match?! Help!! Currently not able to update any apps or icloud info...
If your device is signed into an old ID of yours that is an earlier version of the ID you want to sign in with, do the following:
If you are using iMessage and FaceTime, make sure you are signed into these services with your current ID. If they are signed into the old ID, go to Settings>Messages>Send & Receive and Settings>FaceTime, tap the ID, sign out, then sign back in with your current ID.
Then temporarily recreate the old ID by going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID. Click edit next to the primary email account, change it back to your old email address and save the change. (You should not have to verify the old email account so it doesn’t matter if you no longer have access to it.) Now go to Settings>iCloud, turn off Find My iDevice and enter your current password when prompted (even though it prompts you for the password for your old ID). Then save any photo stream photos that you wish to keep to your camera roll (unless you are using iCloud Photo Library). When finished go to Settings>iCloud, tap Sign Out (or Delete Account if you are not running iOS 8) and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud). Next, go back to https://appleid.apple.com and change your primary email address back to the way it was. Now you can go to Settings>iCloud and sign back in with your current iCloud ID and password (your data will download back to your device). -
Transaction code to change group indicator & group number of a routine
Transaction code to change group indicator & group number of a routine
Post Author: paul.carpenter
CA Forum: Formula
Sorry for the ignorance. I did a little more playing, created a group summary count, then checked it against my record count per group.
All set now! -
Profit center group number on the report painter report.
Hi,
We have a client requirement where we have to develop Profit center by Functional Area report by using report painter report functionality, however we are able to bring profit center group description on to the report as per the requirement, but not able to get profit center group number displayed on the report.
Can anyone please advice me if we can get the Profit center group number displayed on the report in Report painter report. Else let me know if we can get the requirement met by an ABAPER.Hi.
First of all, through transaction GS01 create a set ID for profit centers.
Give table GLPCT, let the set type be the default (basic set) and give field name RPRCTR. Then define the range of profit centers you want. If you want all the profit centers give * in the "from value field".
Then create a variable through transaction GS11. Give table and field as above, choose variable type set and at the default set field choose the set you created.
Finally, at report painter go to Edit/General Data Selection and select profit center.
Check both flags (for entering sets and variables) and give at the form field the variable you've made.
Now the progit center group will be available in the selection screen with default value the set you've made.
Regards -
SAP R/3 instance does not match the number of columns in schema error
Hi Gurus,
Badly need your help, I am currently on dead end here, I cant' think of any resolution for this error message, I have tried almost everything trying to resolve it. Kindly advise..
error msg:* 1306806 3342 R3S-140113 3/23/2010 9:54:47 AM The number of table columns <0> in an R/3 instance does not match the number of columns <8> in schema. Operation*
source: R/3 database
target: Oracle 10G DBase
Tool: Busines Objects Data Integrator 11.7
Many Thanks!
Randy Reyes
PhilippinesHello,
Maybe the following is applicable in your case:
I don't know exactly what you are doing in the BOBJ system but are you using an RFC read table function?
If yes this may be the problem. RFC ReadTable is OK to do some tests but is not scalable. Plus there is a limitation
with the RFC_READ_TABLE function in terms of number of characters returned (up to 512 characters), you
should use R/3 dataflow instread:
Please find below the link which explains how to use the R/3 Dataflow:
https://www.sdn.sap.com/irj/scn/wiki?path=/display/bobj/readingviaABAP
I hope this helps,
Best Regards,
Des -
Hi,
We are using LSMW for Routing data upload.
The "Group" field in the CA01 screen is giving a problem.
The Group number, (which is generated internally) which was used for uploading the previous record is remaining in the field while uploading the next record also, due to which the system is not accepting the Group Counter 01 each time.
Any suggestions please
Thanking you
RamakanthHi,
If this problem is with Routing Group Number, then the Set-get parameters for the Group number must be activated.
If it is active, immediately after coming back to the CA01 screen automatically the Group Number will appear on the screen.
So, deactivate this in SPRO --> Production --> Basic data --> Routing.
Hope this helps..
Regards,
Siva -
Customer Account Group Number Range
Hi Guru's,
The Customer Account Group Number Range has currently taking 10 digits. But my client wants to be 12 digits.
Could you please guide me, to do the necessary setting for the same.
Kindly suggest.
thanking you,
regards,
SreeniDear Sreeni,
You can't change standard customer no range flied width.
You can create a new ZTABLE with 12digits.
regards
natraj -
ORA-15042: ASM disk "2" is missing from group number "1"
Hi,
I'm working on an Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Automatic Storage Management option.
Into the ASM I had 3 diskgroups:
- ARCHIVELOG (4 disks)
- ONLINELOG (1 disks)
- DATA (10 disks)
When I try to startup the ASM instance I got:
A-15042: ASM disk "2" is missing from group number "1"The diskgroup won't be mounted.
I would like to remove that disk and later add a new one.
I can I do that?
I'm not able to mount the ARCHIVELOG diskgroup.
I tried the command
SQL> alter diskgroup archivelog drop disk ARCH3 force;
alter diskgroup archivelog drop disk ARCH3 force
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15001: diskgroup "ARCHIVELOG" does not exist or is not mountedThanks in advance,
Samuel
Edited by: Samuel Rabini on Jan 10, 2012 4:11 PMAs that database is on AWS, I tried this:
- drop diskgroup archivelog
- detach of those 4 disks
- create new 4 disks
- attach new disks
- assign those disks to ASM with oracleasm utilty
- create diskgroup archivelog
It worked.
But because I was on AWS and more because it was the ARCHIVELOG diskgroup.
What would I had to do if it was the DATA diskgroup?
Thanks
Maybe you are looking for
-
Firefox 29.0.1 crashes on windows 7
Hi I also have problems with FireFox crashing since 29.0.1. Here is a list of all BP issues: bp-98ea3800-6cb4-46b9-ab45-d3b242140530 30/05/2014 11:56 bp-3fdf2f42-026e-40f8-8c61-de6342140523 23/05/2014 10:43 bp-36248d79-5f55-4c2f-9211-ca3222140515 15/
-
Billing document to FI posting - negative posting on credit.
Hi all.. I have the following situation : Sales order with a discount condition. After the billing the system generates the accounting note: ZRO1 1 01 11 client 847,88 EUR A1 ZRO1 2 50 70100000 Re
-
Why the samples of 10_MessageChannel which run using a lot of memory (330M)
wether many pthreads communiation with each other , would prompt flacc alloc a lot of memory
-
How to list "unowned" files on my filesystem
I'd like to get a listing of all files on my filesystem that are not owned by any currently-installed packages. I need to specify which directories to exclude, such as /var, /proc, /dev, /tmp, etc. Is there a tool/utility to do that? I could write
-
We have a large complex application and we are starting to run out of room in the weblogicclasspath on windows and unix. We use lots of 3rd party jars to make our applicaiton work, like mail.jar,activation.jar,xerces.jar,xalan.jar and many more. Betw