0

I've a problem with a sorting JS plugin for my tables. It's named "Sortable". When you checkout the documentation of this plugin you can find out that you can define your custom sorting types:

https://github.hubspot.com/sortable/api/options/

So I've defined my custom filter and named it price:

sortable.setupTypes([{
    name: "numeric", defaultSortDirection: "descending", match: function (a) {
        return a.match(d)
    }, comparator: function (a) {
        return parseFloat(a.replace(/[^0-9.-]/g, ""), 10) || 0
    }
}]);

It works particular great but when I add a refund price it works not correctly:

My normal price: 2.372,11 €
My refund price: 765,38 €0,00 €

When the function extracts the refund price, the outcome looks like this: 765,38 € 0,00 € but I must look like this 000.

So I've setup my regex this way /[^0-9-]/g but it's not filtering the del price. Logically the regex needs to get modified the way that it starts after the first €_ or something like this.

Is this possible? If yes, how?

2 Answers 2

2

I would go with something like this

a.replace(/^.*?([0-9]+),([0-9]+)\s*€\s*$/, "$1$2")

https://regex101.com/r/FHOYja/1

Sign up to request clarification or add additional context in comments.

3 Comments

Looks good but enter this here like a value: 2.076,14 € seems to be an issue.
@Mr.Jo replace ([0-9]+),([0-9]+)with ([0-9]*).?([0-9]+),([0-9]+) and your replace with $1$2$3. This includes a optional sumber block with a following dot at the start of the price => ^.*?([0-9]*).?([0-9]+),([0-9]+)\s*€\s*$
Thanks guys for your help! Works great :o
0

A regex to grab everything after the first "€ " would be (?<=€ ).*$ example on regex101:https://regex101.com/r/pULCel/1

1 Comment

Regex101 reports a pattern error. That's because lookbehinds are not officially supported - AFAIK, Chrome has them but not all browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.