I'm trying to create cypher-statements for import using neo4j-shell. I'm using version 2, M3. And I'm somewhat in the dark as to what characters I should escape in the properties. Heres an example:
MATCH (artist:Artist) WHERE artist.kunstnernavn = 'Ditlev Blunck'
CREATE (artwork:Artwork {titel:'Christian IV's vision på slottet Rothenburg',inventarnummer:'KMS64',datering:'-4622274825',teknik:'Olie på lærred',optagelse:'\\foto-02\globus\globus\GLOBUS 2011\kms64.jpg '})
CREATE (artist)-[:CREATED_ARTWORK]->(artwork);
I have tried to escape "\" by %5C but then I get an error on globus%5C .. apparantly s% is a special character in that context. Same goes for titels with " -h" .. apparantly interpreted as an option.
Where can I find docs specifying this?
thanx,
Thorbjørn
Try using the back-tick character (`) to quote your strings.
The neo4j syntax docs gloss over this feature, but usage examples can be found across the site.
Related
I'm trying to get Tweets using twarc2 on terminal like this.
twarc2 search --archive --start-time "2017-10-16” ‘(“#metoo”) -is:retweet lang:en' --limit 1000000 tweets.json
However, after I put the request above, I get
dquote>
It seems that this appears when you use a single quotation and a double quotation. How can I avoid this?
i think the double quote is not necessary. otherwise you can use the escape \ "
You don’t have a single quote ending the command (or, you’ve used a smart quote not a straight quote).
Hi I've been struggling with this for the last hour and am no closer. How exactly do I strip everything except numbers, commas and decimal points from a rails string? The closest I have so far is:-
rate = rate.gsub!(/[^0-9]/i, '')
This strips everything but the numbers. When I try add commas to the expression, everything is getting stripped. I got the aboves from somewhere else and as far as I can gather:
^ = not
Everything to the left of the comma gets replaced by what's in the '' on the right
No idea what the /i does
I'm very new to gsub. Does anyone know of a good tutorial on building expressions?
Thanks
Try:
rate = rate.gsub(/[^0-9,\.]/, '')
Basically, you know the ^ means not when inside the character class brackets [] which you are using, and then you can just add the comma to the list. The decimal needs to be escaped with a backslash because in regular expressions they are a special character that means "match anything".
Also, be aware of whether you are using gsub or gsub!
gsub! has the bang, so it edits the instance of the string you're passing in, rather than returning another one.
So if using gsub! it would be:
rate.gsub!(/[^0-9,\.]/, '')
And rate would be altered.
If you do not want to alter the original variable, then you can use the version without the bang (and assign it to a different var):
cleaned_rate = rate.gsub!(/[^0-9,\.]/, '')
I'd just google for tutorials. I haven't used one. Regexes are a LOT of time and trial and error (and table-flipping).
This is a cool tool to use with a mini cheat-sheet on it for ruby that allows you to quickly edit and test your expression:
http://rubular.com/
You can just add the comma and period in the square-bracketed expression:
rate.gsub(/[^0-9,.]/, '')
You don't need the i for case-insensitivity for numbers and symbols.
There's lots of info on regular expressions, regex, etc. Maybe search for those instead of gsub.
You can use this:
rate = rate.gsub!(/[^0-9\.\,]/g,'')
Also check this out to learn more about regular expressions:
http://www.regexr.com/
text.scan(/\"[\d\w\s\+\-\*\/]*\"/)
I'm simply looking to find any thing within quotations that can contain letters, numbers, spaces, plus, minus, star, or forward slash. Everything works great in console. Each of the following works in a browser:
"abc"
"123"
"x-1" or "x - 1"
"x/1" or "x / 1"
But the plus sign and star fail in a browser (despite working fine in console with the same regex). Does anyone have any ideas?
Edit #1: I'm performing a quick gsub to add some formatting to the results of the scan. If the quotations have a plus or star in them, they don't even get picked up by the scan. The same code and text pasted in console works just fine.
Edit #2: I figured out a better way to frame this question without extraneous details and got the answer. "Why can't I perform a gsub on each of the results from a scan if the result contains regex special characters?"
Turned out that this problem was related to regexp string insertion (/#{whatever}/) not escaping special characters - manually escaping clears it up (/#{Regexp.escape(whatever)}/). See this question for a full example/explanation.
I don't know what do you mean "work in browser" but I'm making an assumption that you're trying to parse an URL. In URL the + & * signs can be converted to %2B & %2A respectively.
Try this regexp:
/"[(\d\w\s\+\-\*\/|%2B|%2A)]+"/
...or decode URL before parsing.
Could anybody help me make a proper regular expression from a bunch of text in Ruby. I tried a lot but I don't know how to handle variable length titles.
The string will be of format <sometext>title:"<actual_title>"<sometext>. I want to extract actual_title from this string.
I tried /title:"."/ but it doesnt find any matches as it expects a closing quotation after one variable from opening quotation. I couldn't figure how to make it check for variable length of string. Any help is appreciated. Thanks.
. matches any single character. Putting + after a character will match one or more of those characters. So .+ will match one or more characters of any sort. Also, you should put a question mark after it so that it matches the first closing-quotation mark it comes across. So:
/title:"(.+?)"/
The parentheses are necessary if you want to extract the title text that it matched out of there.
/title:"([^"]*)"/
The parentheses create a capturing group. Inside is first a character class. The ^ means it's negated, so it matches any character that's not a ". The * means 0 or more. You can change it to one or more by using + instead of *.
I like /title:"(.+?)"/ because of it's use of lazy matching to stop the .+ consuming all text until the last " on the line is found.
It won't work if the string wraps lines or includes escaped quotes.
In programming languages where you want to be able to include the string deliminator inside a string you usually provide an 'escape' character or sequence.
If your escape character was \ then you could write something like this...
/title:"((?:\\"|[^"])+)"/
This is a railroad diagram. Railroad diagrams show you what order things are parsed... imagine you are a train starting at the left. You consume title:" then \" if you can.. if you can't then you consume not a ". The > means this path is preferred... so you try to loop... if you can't you have to consume a '"' to finish.
I made this with https://regexper.com/#%2Ftitle%3A%22((%3F%3A%5C%5C%22%7C%5B%5E%22%5D)%2B)%22%2F
but there is now a plugin for Atom text editor too that does this.
I'm trying to access a network path in my ruby script on a windows platform in a format like this.
\\servername\some windows share\folder 1\folder2\
Now If I try to use this as a path, it won't work. Single backslashes are not properly escaped for this script.
path = "\\servername\some windows share\folder 1\folder2\"
d = Dir.new(path)
I tried everything I could think of to properly escape slashes in the path. However I can't escape that single backslash - because of it's special meaning. I tried single quotes, double quotes, escaping backslash itself, using alternate quotes such as %Q{} or %q{}, using ascii to char conversion. Nothing works in a sense that I'm not doing it right. :-) Right now the temp solution is to Map a network drive N:\ pointing to that path and access it that way, but that not a solution.
Does anyone have any idea how to properly escape single backslashes?
Thank you
Just double-up every backslash, like so:
"\\\\servername\\some windows share\\folder 1\\folder2\\"
Try this
puts '\\\\servername\some windows share\folder 1\folder2\\'
#=> \\servername\some windows share\folder 1\folder2\
So long as you're using single quotes to define your string(e.g., 'foo'), a single \ does not need to be escaped. except in the following two cases
\\ works itself out to a single \. So, \\\\ will give you the starting \\ you need.
The trailing \ at the end of your path will tries to escape the closing quote so you need a \\ there as well.
Alternatively,
You could define an elegant helper for yourself. Instead of using the clunky \ path separators, you could use / in conjunction with a method like this:
def windows_path(foo)
foo.gsub('/', '\\')
end
puts windows_path '//servername/some windows share/folder 1/folder2/'
#=> \\servername\some windows share\folder 1\folder2\
Sweet!