Forums Register Login

RowFilters and doubles as Strings not working as expected.

+Pie Number of slices to send: Send
Hi All,
e
I'm working with RowFilters and trying to get the following to happen.

One of my columns might be doubles. there might be several values like

Column FOO
-------------
392.444444
433.33333
123.333354
2.33331


and I have a separate table that I use to filter these columns

but I'm looking for pattern matching so if the first character that is entered is 3 my table is filtered down 4 my table is filtered down to

Column FOO
-------------
392.444444
433.33333
123.333354

This all works fantastic

however I seem to be having a problem with the .

for example if my filter is 3. my filter seems to be using the . as a "there is a character there"

so the above filtering wont' change. but if I add a 3.2 my results would be

Column FOO
-------------
392.444444

String value = "3.2"
filters.add(RowFilter.regexFilter("(?i)" + value, k));

what I would prefer is that the . be the decimal place, so if I type 3. my filter would be

Column FOO
-------------
433.33333
123.333354

and If I typed 3.2 as my filter, then I would have no results.


Any help would be appreciated.
+Pie Number of slices to send: Send
The dot is a metacharacter in regex and matches *any* character. To match a literal dot, you need to escape it. In a String literal, that would mean prefacing it with a double backslash; in a String input, a single backslash would suffice. Or you could process the entire input, prefacing it and suffixing it with the regex quote characters "\\Q" and "\\E"
+Pie Number of slices to send: Send
 

Darryl Burke wrote:The dot is a metacharacter in regex and matches *any* character. To match a literal dot, you need to escape it. In a String literal, that would mean prefacing it with a double backslash; in a String input, a single backslash would suffice. Or you could process the entire input, prefacing it and suffixing it with the regex quote characters "\\Q" and "\\E"



Brilliant!


except I'm still confused. I understand completely what you are saying, but I'm having a hard time making it work.

I've tried String value = "3\\.2"
as well as String value = "\\Q3.2\\E"

as well as some other things, but it's still working the same
+Pie Number of slices to send: Send
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

Include several inputs (possibly as an array or List) and the expected and actual outputs.
+Pie Number of slices to send: Send
Sure, sorry i was trying to keep it pretty general, but mostly because my code is in several different places.

Mostly I'm looking at the following




The filtering model works great outside of the "."
+Pie Number of slices to send: Send
 

Darryl Burke wrote:
Include several inputs (possibly as an array or List) and the expected and actual outputs.




So basically if value was 3.2

and my values were
1233.2
332.42
2443.432
321.123
321123123.1
3.2

I'd only want the 1233.2 and the 3.2 back or the same if I had just typed 3.
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 496 times.
Similar Threads
Problem with filtering JTable (AbstractTableModel)
Regex to filter any word in any order in column of JTable?
Can row filters be combined?
JTable rowFilter - is case insensitive possible?
Get data filter in JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:12:43.