Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » RegEx Help
RegEx Help [message #47142] Tue, 20 December 2016 13:58 Go to next message
deep is currently offline  deep
Messages: 197
Registered: July 2011
Location: Bangalore
Experienced Member
Hi

WIN10, Latest UPP code base using git.

My RegEx is
RegExp r0("((\\w+)\\s(\\w+)\\s(\\w+))");

My String is
"one two three one two three one two three"

for "r0.GlobalMatch("one two three one two three one two three")"

I am expecting match count to be 3 and
with result as

one two three
one two three
one two three



I am using following code
#include <Core/Core.h>

#include <plugin/pcre/Pcre.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	String s;
	RegExp r0("((\\w+)\\s(\\w+)\\s(\\w+))");
	if(r0.GlobalMatch("one two three one two three one two three"))
	{
		DUMP(r0.GetCount());
		for(int i = 0; i < r0.GetCount(); i++)
		    s << r0[i] << '\n';
		s << "---\n";
    } else if(r0.IsError())
	    s << r0.GetError() << '\n';

	s << "------------------------------\n";

	RegExp r1("(\\w+)", RegExp::UNICODE);
	int i = 0;
	while(r1.GlobalMatch("hello 4 ho 55 uuu iii pp 99 baby too swistak"))
	{
		for(int i = 0; i < r1.GetCount(); i++)
			s << r1[i] << '\n';
    }
	if(r1.IsError())
	    Cout() << r1.GetError() << '\n';
	DUMP(s);
	Cout() << s ;
}


and I get
r0.GetCount() = 4
s = one two three
one
two
three
---
------------------------------
hello
4
ho
55
uuu
iii
pp
99
baby
too
swistak



If I check this on regex101.com
I get result as expected.

https://regex101.com/r/2wPaVN/1

What can I change in code.

-----------
I checked with command line pcre2test
Working as expected

index.php?t=getfile&id=5100&private=0
  • Attachment: Image 275.png
    (Size: 10.39KB, Downloaded 130 times)


Warm Regards

Deepak

[Updated on: Wed, 21 December 2016 08:16]

Report message to a moderator

Re: RegEx Help [message #47145 is a reply to message #47142] Wed, 21 December 2016 08:40 Go to previous message
deep is currently offline  deep
Messages: 197
Registered: July 2011
Location: Bangalore
Experienced Member
Hi,

I missed the later part of code. It is there in my code sample.

It is working. "GlobalMatch" should run in while loop.

RegExp r0("((\\w+)\\s(\\w+)\\s(\\w+))");
while(r0.GlobalMatch("one two three one1 two1 three1 one2 two2 three2"))
{
	DUMP(r0.GetCount());
	for(int i = 0; i < r0.GetCount(); i++)
	    s << r0[i] << '\n';
	s << "---\n";
}
DUMP(s)


And output
one two three
one
two
three
---
one1 two1 three1
one1
two1
three1
---
one2 two2 three2
one2
two2
three2
---


Warm Regards

Deepak

[Updated on: Wed, 21 December 2016 08:45]

Report message to a moderator

Previous Topic: Problem with dialogs
Next Topic: IdeCalc -- ERROR: void.sin(): (0,15): 'sin' is not a lambda
Goto Forum:
  


Current Time: Wed Nov 20 02:37:46 CET 2019

Total time taken to generate the page: 0.02207 seconds