Apache Velocity and Escaping # followed by $ - velocity

Question regarding Velocity and I cannot seem to find an answer anywhere online... Maybe it's really that obvious, anyway, the question:
I have a variable called $link and when I want to use it as a hyperlink to an anchor I use e.g.:
something
And I get that as a literal output...
How can I get if $link = "bla":
something
as output?
And also the same problem with:
something
to get as
something
Thanks!!

Ok, found the answer:
something
and
something

Related

regex limitations within live template / can use live-template functions as replacement?

I'm removing builder pattern on multiple places. Following example would help me with the task, but mainly I'd like to learn how to use live templates more.
Preexisting code:
Something s = s.builder
.a(...)
.b(bbb)
.build();
and I'd like to remove it to:
Something s = new Something();
s.setA(...);
s.setB(bbb);
part of it can be trivially done using intellij regex, pattern: \.(.*)$ and replacement .set\u$1. Well it could be improved, but lets keep it simple.
I can create surround live template using variable:
regularExpression(SELECTION, "\\.(.*)", "\\u$1")
but \\u will be evaluated as u.
question 1: is it possible to get into here somehow \u functionality?
but I might get around is differently, so why not try to use live temlate variable:
regularExpression(SELECTION, "\\.(.)(.*)", concat(capitalize($1), "$2"))
but this does not seem to work either. .abc is replaced to bc
question 2: why? How would correct template look like? And probably, if it worked, this would behave incorrectly for multiline input. How to make it working and also for multiline inputs?
sorry for questions, I didn't find any harder examples of live templates than trivial replacements.
No, there is no \u functionality in the regularExpression() Live Template macro. It is just a way to call String.replaceAll(), which doesn't support \u.
You can create a Live Template like this:
set$VAR$
And set the following expression for the $VAR$ variable:
capitalize(regularExpression(SELECTION, "\\.(.*)", "$1"))

Karate pathMatches exclusion

I would like to have possibility in Karate to match all paths except /example/path, to have something like this:
pathMatches ('!/example/path')
Is there such possibility?
You can use the requestUri variable which will be always set automatically. The nice thing about the design is you can use "normal" Java Script and achieve any combination you want, pathMatches() is just pre-defined for convenience.
So this should get you what you want, try it !
Scenario: !requestUri.startsWith('/example/path')
EDIT: silly me, I just realized that you have a much better option, again "because JavaScript". This will work !
Scenario: !pathMatches('/example/path')

Object name contains more than the maximum prefixes allowed

I have seen a lot of questions about this but I couldn't find the correct answer for me which works.
The object which triggers the problem is like
test123.de.company.com.Database.dbo.Table
Test123.de.company.com
is the database Server.
Object name contains more than the maximum prefixes allowed
I have tried to write it like this [test123.de.company.com].Database.dbo.Table just like [test123.de.company.com].[Database].[dbo].[Table]
Can you tell me what's wrong with this?
Please try this:
["test123.de.company.com"].[Database].[dbo].[Table]
OP also encountered a new problem after implementing this solution above. OP said:
Thank you! This worked for me. To be more precise, the join is for a
view and if I save/close and then later get back to the design option
the quote marks are removed and there is [test123.de.company.com] left
over and the error returns. Is there a way to keep them fixed?
Otherwise if I change anything I always have to add the quote marks
again and again
Then with the help of DaleK that problem also was solved. DaleK:
Don't use the design option, script it as alter instead

Chai.js - Check if string contains substring from a list

I'm using chai.js writing some automation tests. I have a string:
url(http://somewhere.com/images/myimage.png)
I want to do something like:
expect(thatSelectedItem).contains.any('jpg', 'png', 'gif')
However can't seem to find anything in chai.js
Any have any suggestions - read the page http://chaijs.com/api/bdd/ however no luck.
Any help appreciated.
Thanks.
With plain Chai (no additional plugins), you can use match:
expect(thatSelectedItem).to.match(/(?:jpg|png|gif)/)
expect(thatSelectedItem).to.contain.oneOf(['jpg', 'png', 'gif'])
This lands with v4.3.0 (docs). oneOf can be chained with contain, contains, include and includes, which will work with both arrays and strings. It's strongly recommended to use because the error messages you get with it are much cleaner.

Regex to replace asterisk characters with html bold tag

Does anyone have a good regex to do this? For example:
This is *an* example
should become
This is <b>an</b> example
I need to run this in Objective C, but I can probably work that bit out on my own. It's the regex that's giving me trouble (so rusty...). Here's what I have so far:
s/\*([0-9a-zA-Z ])\*/<b>$1<\/b>/g
But it doesn't seem to be working. Any ideas? Thanks :)
EDIT: Thanks for the answer :) If anyone is wondering what this looks like in Objective-C, using RegexKitLite:
NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:#"\\*([0-9a-zA-Z ]+?)\\*" withString:#"<b>$1<\\/b>"];
EDIT AGAIN: Actually, to encompass more characters for bolding I changed it to this:
NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:#"\\*([^\\*]+?)\\*" withString:#"<b>$1<\\/b>"];
Why don't you just do \*([^*]+)\* and replace it with <b>$1</b> ?
You're only matching one character between the *s. Try this:
s/\*([0-9a-zA-Z ]*?)\*/<b>$1<\/b>/g
or to ensure there's at least one character between the *s:
s/\*([0-9a-zA-Z ]+?)\*/<b>$1<\/b>/g
I wrote a slightly more complex version that ensures the asterisk is always at the boundary so it ignores hanging star characters:
/\*([^\s][^\*]+?[^\s])\*/
Test phrases with which it works and doesn't:
This one regexp works for me (JavaScript)
x.match(/\B\*[^*]+\*\B/g)