apache camel <simple trim="true" is not working - apache-camel

I'm reading a simple content from a file, say "80631". i validate it against a regex("^\d+$") to check it's just digits. But the validation fails. When i inspect the content read from the file it's something like "80631 ". I tried to trim the whitespace with , but it didn't work. Do we have any other way to trim the whitespace?
<camel:setProperty propertyName="messageId">
<simple trim="true">${body}</simple>
</camel:setProperty>

You should likely show the code to get better help. But <simple trim="true"> ... </simple> is trimming the output of the expression.
Its not for trimming message body.
You need to use message transformation beforehand to trim the message body. Or write a regular expression that ignore leading/ending whitespace.

Related

React-csv not allowing me to change or remove enclosing characters

I am trying to export a csv using react-csv. The documentation says that I should be able to modify the enclosing character with an enclosingCharacter prop, but it doesn't seem to make a difference when I set it. It always uses a quotation mark as the enclosing character. I've tried single quotes, false, null. Nothing works. Ideally, I'd like for there to be no enclosing characters and just use commas for the delimiter. What am I doing wrong?
<CSVLink
data={this.state.csvData}
filename="sample.csv"
enclosingCharacter={`'`}
/>
Current output looks like this: "data1","data2","data3"
Desired output should look like this: data1,data2,data3

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

Regex without spaces [duplicate]

I am writing a regular expression(regex) for adding multiple email ids in an input box with following conditions:
Multiple email ids must be separated with comma ,
Need to have atleast one email id
There should not be any whitespaces in input field.
So i created this regex:
^(([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$
I tested it in regex101.com and its working like a charm https://regex101.com/r/bU7rU8/1
But when i integrate it with code, it works, but fails on leading and trailing whitespace.
Here is the demo link: http://jsfiddle.net/2G8gA/330/
AngularJS trims the input by default, so you need to use ng-trim="false" in order to pass leading and trailing whitespace to your pattern regex.
See documentation:
ngTrim (optional)
If set to false Angular will not automatically trim the input. This parameter is ignored for input[type=password] controls, which will never trim the input.
(default: true)
Do you want leading/trailing spaces allowed on the whole string, or around each individual address?
For the former your regex should be
/^(\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/
and for the latter
/^(\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}\s*)+([,.](\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/

Regular Expression Generation for AngularJS ng-pattern

I'm using a regex to validate a form input. So basically a user can input "SELECT some_name of select_match".
So far I have the regex: \bSELECT\b \bof select_match\b
The last part is the middle part, which I think should be [a-zA-Z] but I'm not sure how to place it in the middle. I've read multiple pages but can't get it to work.
Also preferably I'd like the regex to ignore spaces between "SELECT" and of "select_match". Meaning that SELECT blabla of select_match and SELECT blabla of select_match would both be validated as correct.
Can anyone tell me how to do this? Thank you.
If I understood you correctly, this should work:
/^SELECT\s+(\w+)\s+of select_match$/
Notes:
This allows any number of spaces between "SELECT" and the match_name; and between the match_name and the "of" (but, at least 1. To change to at least 0, change the \s+ to a \s*)
After that, the rest of the string must be exactly like that (same spaces and words exactly).
The match_name will be in match group 1.
If this doesn't work, show a bit of your code (where you use it) and we can try to find the problem.
Note: If you are using it in ng-pattern lose the "/"s (being the pattern: ^SELECT\s+(\w+)\s+of select_match$).
Note2: If you are using it in a string, remember you might need to escape every "\" (making it a "\", and the result: ^SELECT\\s+(\\w+)\\s+of select_match$

Restricting file types in AngularJS with HTML input type="file"

So my HTML passes a file into AngularJS, and it is named as myFile.
So I use:
console.log($scope.myFile.type);
and it prints out 'application/pdf'.
But when I use this line:
if ($scope.myFile.type == 'application/pdf'){
// some stuff here
}
or
($scope.myFile.type == {'image/jpeg': fileMimeType})
Those will not ever be equal to true. I have no idea how to run this comparison anymore, and would appreciate snippets that would allow me to somehow create this comparison.
Thanks.
I wish i could make comments, but alas i do not have enough points. Did you try console.log( typeof $scope.myFile.type); to make sure it was a string? Also did the output itself have single quotes in it? because if it does have the quotes in it you'll either need to strip those or compare with the quotes in your string.

Resources