admin管理员组

文章数量:1122846

can anyony help me with what is the expeted input string that would be accepted by the regex in this method?

Message = input is a string

fun getId(Message) = (Message match /betalning_maltid_\{id:([0-9]+)\}/)[1]

This in anypoint studio useing mule and DataWeave

I am hopeing to use this function a to get the program to work but I am stuck on this probmlem on understanding what kind of string it will accept

I have tried

"betalning_maltid_id:099"
"betalning_maltid_099"
"099" 

from my understanding of this method and regex

(
Message = input String
match = method/function "A Java regex for matching characters in the text."
/ = start of the regex
betalning_maltid_ = betalning_maltid_
backward slash{ = I read it as dataweave should not care about the {
id: = id: or changed meaning because it is inclosed in {}
([0-9]+) = starts with a number and everything after is number
backward slash} = I read it as dataweave should not care about the {
/ = end of the regex
)[1] = we expect atleast two resluts and we want the second one.


if I instead remove the { and } and enter String "betalning_maltid_id:564"

var myString = "betalning_maltid_id:564"
myString match /betalning_maltid_id:([0-9]+)/

I get the result

    [
        "betalning_maltid_id:370",
        "370"
    ]

Any ideas how I should format my input do still keep { and } in the code?

can anyony help me with what is the expeted input string that would be accepted by the regex in this method?

Message = input is a string

fun getId(Message) = (Message match /betalning_maltid_\{id:([0-9]+)\}/)[1]

This in anypoint studio useing mule and DataWeave

I am hopeing to use this function a to get the program to work but I am stuck on this probmlem on understanding what kind of string it will accept

I have tried

"betalning_maltid_id:099"
"betalning_maltid_099"
"099" 

from my understanding of this method and regex

(
Message = input String
match = method/function "A Java regex for matching characters in the text."
/ = start of the regex
betalning_maltid_ = betalning_maltid_
backward slash{ = I read it as dataweave should not care about the {
id: = id: or changed meaning because it is inclosed in {}
([0-9]+) = starts with a number and everything after is number
backward slash} = I read it as dataweave should not care about the {
/ = end of the regex
)[1] = we expect atleast two resluts and we want the second one.


if I instead remove the { and } and enter String "betalning_maltid_id:564"

var myString = "betalning_maltid_id:564"
myString match /betalning_maltid_id:([0-9]+)/

I get the result

    [
        "betalning_maltid_id:370",
        "370"
    ]

Any ideas how I should format my input do still keep { and } in the code?

Share Improve this question edited Nov 27, 2024 at 2:45 DuesserBaest 1,9347 silver badges21 bronze badges asked Nov 21, 2024 at 15:49 John Q. PublicJohn Q. Public 91 silver badge1 bronze badge 1
  • 1 It is not clear what is exactly the input, which data type it is and what was the result. "Don't work" is not a result or error that can be helpful for others to understand the issues. Are the inputs to the script or to the function? Since the question is about the regex, you should remove all other business logic from the problem and make it about the function with the regex. That's what a minimal reproducible example is about. Be clear about the exact input that was tested so others can reproduce the issue. Help others to help you. Use edit to modify the question as suggested. – aled Commented Nov 21, 2024 at 20:56
Add a comment  | 

1 Answer 1

Reset to default 1

The curly braces are escaped (\{ and \}) which means they are considered literals. They are missing in your inputs.

Example:

"betalning_maltid_{id:1234}" match /betalning_maltid_\{id:([0-9]+)\}/

Output:

[
  "betalning_maltid_{id:1234}",
  "1234"
]

本文标签: Mule function that using match with a regex what kind of string does the function acceptStack Overflow