Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

Expression returns more than one line

0 votes
The expression returns all data for Birth property. How can I force it to stop after returning value for place? Note: in the 'successful' use described by the questioner re: positioning the place value, an extra line was also returned (but not commented on).
in Help by

1 Answer

0 votes

If the expression (?ms).*^\d\sPLAC\s(.*)$ matches, it matches all the text in the custom property. Moreover, * is a greedy quantifier - thus (.*)$ will capture anything from "PLAC " until the end of the text. As a result the $1 replacement will insert all the text right after "PLAC " until the end of the text.

In short, that is the intended behavior.

If you want to extract only the remainder of the line in which "PLAC " occurs for the first time, then you will have to restrict the capturing group accordingly:

(?ms).*^\d\sPLAC\s(.*?)$.*

The question mark turns the * quantifier from a greedy quantifier into a reluctant quantifier (i.e. the following $ will then match the first line ending after PLAC instead of the last).
The trailing .* ensures that the expression still matches all of the text, because the operation will replace the matched text and you do not want to keep any text after the line you are interested in.

Note, this is really not a yEd question but a pure regular expression question. Please see the Java Pattern class documentation for information on how to write Java regular expressions.

by [yWorks] (160k points)
Legal Disclosure | Privacy Policy
...