Global flag for regex in Katalon

Hi, tell me please out of these flags - Match flags [ CASE_INSENSITIVE ] [ MULTILINE ], [ DOTALL ] [ UNICODE_CASE ] [ CANON_EQ ] [ UNIX_LINES ] [ LITERAL ] [ UNICODE_CHARACTER_CLASS` ]
there is a flag to make the GLOBAL regex.?
As in regex101 ?
image

Please have a look at verifyMatch not working with valid Regular Expression

I do not understand what your “global flag” means.

It seems that you want to change the behavior of Katalon Studio for regex pattern matching so that you can specify the flags you want and make it effective throughout a Test Case run. If I am right, as you can see in the above link, specifying flags to regexp is not supported in Katalon Studio.

So my situation is the following:
I created a regex using the regex101 site with global and multiline flags that work very well.
When using regex in Katalon it does not work well, because these flags are not specified.
And I do not know how to do it.
Here’s how I define and use the regex:
Pattern regexPat6 = Pattern.compile (’<((? = [] * (Span)) [^>] *)’, 1)

Matcher mat6 = regexPat6.matcher (d)
//mat6=rr.exec(d)
while (mat6.matches ()) {

String result1 = mat6.group (1)
}

In the top case I use “1” ie MULTILINE, but I need Global.
Is there something similar in Katalon studio that works as the global flag for RegExp?

According to using regex g flag in java - Stack Overflow

Java does not have global flag. You can get all matches via find and group .

Pattern pattern = Pattern.compile("1");
Matcher matcher = pattern.matcher("111");
while (matcher.find()) {
    System.out.println(matcher.group());
}

The output is

1
1
1

Thanks, I understand java does not have the global flag, but something that would work similarly?
I have a piece of HTML code where I search for the “span” tag and I did as you suggested, but from all the code I do not find all the “span”. That’s why I thought that the flags should be specified, because in regex101, everything goes well.
So, is there a solution for me? Can I generally change the search method for the span tag?

 Pattern regexPat =Pattern.compile("<((?=[ ]*(span))[^>]*)")		
	Matcher mat = regexPat.matcher(d)		
	while (mat.matches()) {		 
		System.out.println(mat.group());		
	 }

d- is the variable with my HTML code

Please try the follwing code as a test case in Katalon Studio:

import org.openqa.selenium.WebElement

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')
WebUI.navigateToUrl('http://forum.katalon.com/t/global-flag-for-regex-in-katalon/17706/')

// make sure the page loads
TestObject logoTO = new TestObject()
logoTO.addProperty("xpath", ConditionType.EQUALS, "//img[@id='site-logo']")
WebUI.verifyElementPresent(logoTO, 10)

// grasp all of <span> elements in the page
TestObject spansTO = new TestObject()
spansTO.addProperty("xpath", ConditionType.EQUALS, "//span")
List<WebElement> spanElements = WebUI.findWebElements(spansTO, 10)

// iterate over them
for (int i = 0; i < spanElements.size(); i++) {
	WebElement span = spanElements.get(i)
	println "${i}: \'${span.getText()}\'"
}

This will give you more than 100 <span> elements.

Yes, but I need to return the span element with the attributes of this (style, align, class, id …)

Then, change it a bit:

// iterate over them
for (int i = 0; i < spanElements.size(); i++) {
	WebElement span = spanElements.get(i)
	// you can get access to the attributes of <span> element by various ways
	// http://static.javadoc.io/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebElement.html
	println "${i}: <span id=\"${span.getAttribute('id')}\"" + 
		" class=\"${span.getAttribute('class')}\"" + 
		">${span.getText()}</span>"
}

New code will emit something like this:

0: <span id="ember716" class="ember-view"></span>
1: <span id="" class="header-buttons">Log In</span>
2: <span id="" class="d-button-label">Log In</span>
3: <span id="ember730" class="ember-view"></span>
4: <span id="ember731" class="ember-view"></span>
5: <span id="ember751" class="ember-view"></span>
6: <span id="ember777" class="ember-view"></span>
7: <span id="" class="private-message-glyph"></span>
8: <span id="" class="badge-category-bg"></span>
9: <span id="" class="badge-category clear-badge">Katalon Studio</span>
10: <span id="" class="category-name">Katalon Studio</span>
11: <span id="" class="badge-category-bg"></span>
12: <span id="" class="badge-category clear-badge">Web Testing</span>
13: <span id="" class="category-name">Web Testing</span>
14: <span id="ember806" class="ember-view"></span>
15: <span id="ember807" class="ember-view"></span>
16: <span id="ember815" class="ember-view"></span>
17: <span id="" class="d-label">Jan 15</span>
18: <span id="" class="d-label">4h ago</span>
19: <span id="ember832" class="ember-view"></span>
20: <span id="" class="first username">Valeria_Ciobanu</span>
21: <span id="" class="relative-date">1d</span>
22: <span id="" class="d-button-label">1 Reply</span>
23: <span id="" class="relative-date">1d</span>
24: <span id="" class="relative-date">4h</span>
25: <span id="" class="number">7</span>
26: <span id="" class="number">34</span>
27: <span id="" class="number">2</span>
28: <span id="" class="number">1</span>
29: <span id="" class="post-count">4</span>
30: <span id="" class="post-count">4</span>
31: <span id="" class="first username">kazurayam</span>
32: <span id="" class="relative-date">23h</span>
33: <span id="" class="badge badge-notification clicks">1</span>
34: <span id="" class="first username">kazurayam</span>
35: <span id="" class="relative-date">21h</span>
36: <span id="" class="svg-icon-title"></span>
37: <span id="" class="first username">Valeria_Ciobanu</span>
38: <span id="" class="relative-date">8h</span>
39: <span id="" class="first username">kazurayam</span>
40: <span id="" class="relative-date">8h</span>
41: <span id="" class="hljs-string">"1"</span>
42: <span id="" class="hljs-string">"111"</span>
43: <span id="" class="hljs-keyword">while</span>
44: <span id="" class="hljs-keyword">out</span>
45: <span id="" class="hljs-keyword">group</span>
46: <span id="" class="first username">Valeria_Ciobanu</span>
47: <span id="" class="relative-date">8h</span>
48: <span id="" class="first username">kazurayam</span>
49: <span id="" class="relative-date">7h</span>
50: <span id="" class="hljs-keyword">import</span>
51: <span id="" class="hljs-keyword">import</span>
52: <span id="" class="hljs-keyword">import</span>
53: <span id="" class="hljs-keyword">import</span>
54: <span id="" class="hljs-string">''</span>
55: <span id="" class="hljs-string">'http://forum.katalon.com/t/global-flag-for-regex-in-katalon/17706/'</span>
56: <span id="" class="hljs-comment">// make sure the page loads</span>
57: <span id="" class="hljs-keyword">new</span>
58: <span id="" class="hljs-string">"xpath"</span>
59: <span id="" class="hljs-string">"//img[@id='site-logo']"</span>
60: <span id="" class="hljs-number">10</span>
61: <span id="" class="hljs-comment">// grasp all of <span> elements in the page</span>
62: <span id="" class="hljs-keyword">new</span>
63: <span id="" class="hljs-string">"xpath"</span>
64: <span id="" class="hljs-string">"//span"</span>
65: <span id="" class="hljs-number">10</span>
66: <span id="" class="hljs-comment">// iterate over them</span>
67: <span id="" class="hljs-keyword">for</span>
68: <span id="" class="hljs-keyword">int</span>
69: <span id="" class="hljs-number">0</span>
70: <span id="" class="hljs-string">"${i}: \'${span.getText()}\'"</span>
71: <span id="" class="first username">Valeria_Ciobanu</span>
72: <span id="" class="relative-date">4h</span>
73: <span id="" class="d-button-label">Reply</span>
74: <span id="ember853" class="ember-view"></span>
75: <span id="" class="link-top-line">How to find element by name ?</span>
76: <span id="" class="topic-post-badges"></span>
77: <span id="" class="badge-category-parent-bg"></span>
78: <span id="" class="badge-category-bg"></span>
79: <span id="" class="badge-category clear-badge">Web Testing</span>
80: <span id="" class="category-name">Web Testing</span>
81: <span id="" class="number">1</span>
82: <span id="" class="number">90</span>
83: <span id="" class="relative-date with-year">May '18</span>
84: <span id="" class="link-top-line">Error on line 9</span>
85: <span id="" class="topic-post-badges"></span>
86: <span id="" class="badge-category-parent-bg"></span>
87: <span id="" class="badge-category-bg"></span>
88: <span id="" class="badge-category clear-badge">Web Testing</span>
89: <span id="" class="category-name">Web Testing</span>
90: <span id="" class="number">1</span>
91: <span id="" class="number">26</span>
92: <span id="" class="relative-date with-year">Mar '18</span>
93: <span id="" class="link-top-line">Switching between Tabs in Chrome issue</span>
94: <span id="" class="topic-post-badges"></span>
95: <span id="" class="badge-category-parent-bg"></span>
96: <span id="" class="badge-category-bg"></span>
97: <span id="" class="badge-category clear-badge">Web Testing</span>
98: <span id="" class="category-name">Web Testing</span>
99: <span id="" class="number">2</span>
100: <span id="" class="number">164</span>
101: <span id="" class="relative-date with-year">Oct '18</span>
102: <span id="" class="link-top-line">Not able to drag and drop object from object repository to script</span>
103: <span id="" class="topic-post-badges"></span>
104: <span id="" class="badge-category-parent-bg"></span>
105: <span id="" class="badge-category-bg"></span>
106: <span id="" class="badge-category clear-badge">Web Testing</span>
107: <span id="" class="category-name">Web Testing</span>
108: <span id="" class="number">0</span>
109: <span id="" class="number">32</span>
110: <span id="" class="relative-date with-year">May '18</span>
111: <span id="" class="link-top-line">test cases are getting stuck in IE</span>
112: <span id="" class="topic-post-badges"></span>
113: <span id="" class="badge-category-parent-bg"></span>
114: <span id="" class="badge-category-bg"></span>
115: <span id="" class="badge-category clear-badge">Web Testing</span>
116: <span id="" class="category-name">Web Testing</span>
117: <span id="" class="number">0</span>
118: <span id="" class="number">29</span>
119: <span id="" class="relative-date with-year">Jun '18</span>
120: <span id="" class="badge-category-parent-bg"></span>
121: <span id="" class="badge-category-bg"></span>
122: <span id="" class="badge-category clear-badge">Web Testing</span>
123: <span id="" class="category-name">Web Testing</span>
124: <span id="ember928" class="ember-view"></span>
125: <span id="ember930" class="ember-view"></span>

See http://static.javadoc.io/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebElement.html for the detail API of the org.openqa.selenium.WebElement class.

I guess you might want to read the HTML text from a URL. In that case, I think you should use curl or wget command to download URL and save it into a local text file, then parse the text with your favorite tools (sed, awk, perl, ruby, python, node etc, Of course, groovy and java will do as well).

Katalon Studio and WebDriver is not appropriate tool for getting access to web pages as text, because WebDriver works on the DOM of a web page, not on the HTML text.

Da, aceasta merge bine, dar mie imi trebuie sa il gasesc ca text , nu ca element.
Eu deja am codul ca text, si din el imi trebuie doar partea cu tagu-ul span de deschidere cu atribute , fara continut si cel de inchidere.
Va multumesc mult pentru rabdare si ajutor. Apreciez foarte mult.

by Google Translate, Portuguese → English, I got:

Yes, it works well, but I need to find it as text, not as an element.
I already have the code as text, and from it I just need the part with the opening span tag with attributes, no content and closure.
Thank you very much for your patience and help. I really appreciate it.