perl

Perl regex with pipes

帅比萌擦擦* 提交于 2021-02-05 06:08:34
问题 I'm not exactly a perl monk, so if you could help me digest what does this regex(if it is one) do? my $pathHere = "/some/path/to/file"; my $pathThere = "/some/path/"; $pathHere =~ s|$pathThere||; Perl is not exactly my everyday tool, so I am quite shy on knowledge - I guess it subs the match to the var value, but guessing is not the way to go - the pipes throw me off... Thanks 回答1: In Perl you'd normally use the / as a delimiter in the regexp. $pathHere =~ s/abc/def/; # replace 'abc' with

Perl regular expression to find a exact word

空扰寡人 提交于 2021-02-05 05:51:26
问题 I want to find the word sprintf in my code. What Perl regular expression should be used? There are some lines which have text like sprintf_private , which I want to exclude, but need just sprintf . 回答1: You must use \b at the words' border: /\bsprintf\b/ 回答2: If you want to find all occurrences of sprintf on lines that do not contain sprintf_private , you might use a pair of regexes: while( my $line = <DATA> ) { next if $line =~ m/\bsprintf_private\b/; while( $line =~ m/\bsprintf\b/g ) {

Trouble escaping dollar sign in Perl

会有一股神秘感。 提交于 2021-02-05 05:41:11
问题 I'm getting a bunch of text from an outside source, saving it in a variable, and then displaying that variable as part of a larger block of HTML. I need to display it as is, and dollar signs are giving me trouble. Here's the setup: # get the incoming text my $inputText = "This is a $-, as in $100. It is not a 0."; print <<"OUTPUT"; before-regex: $inputText OUTPUT # this regex seems to have no effect $inputText =~ s/\$/\$/g; print <<"OUTPUT"; after-regex: $inputText OUTPUT In real life, those

Trouble escaping dollar sign in Perl

我是研究僧i 提交于 2021-02-05 05:40:49
问题 I'm getting a bunch of text from an outside source, saving it in a variable, and then displaying that variable as part of a larger block of HTML. I need to display it as is, and dollar signs are giving me trouble. Here's the setup: # get the incoming text my $inputText = "This is a $-, as in $100. It is not a 0."; print <<"OUTPUT"; before-regex: $inputText OUTPUT # this regex seems to have no effect $inputText =~ s/\$/\$/g; print <<"OUTPUT"; after-regex: $inputText OUTPUT In real life, those

Split binary number into groups of zeros and ones

隐身守侯 提交于 2021-02-05 05:35:05
问题 I have a binary number, for example 10000111000011 , and want to split it into groups of consecutive 1s and 0s, 1 0000 111 0000 11 . I thought that's a great opportunity to use look-arounds: my regex uses a positive look-behind for a digit (which it captures for later backreferencing), then a negative look-ahead for that same digit (using a backreference), so I should get a split whenever a digit is followed by a digit that is not the same. use strict; use warnings; use feature 'say'; my $bin

How to use word break, asterisk, word break in Regex with Perl?

蹲街弑〆低调 提交于 2021-02-04 22:21:12
问题 I have a complexe precompiled regular expression in Perl. For most cases the regex is fine and matches everything it should and nothing it shouldn't. Except one point. Basically my regex looks like: my $regexp = qr/\b(FOO|BAR|\*)\b/; Unfortunately m/\b\*\b/ won't match example, * . Only m/\*/ will do which I can't use because of false positives. Is there any workaround? from the comments - false positives are: ** , example* , exam*ple what the regex is intended for? - It should extract

replacing a placeholder in a html file with 1-n specific values defined in a config.json using shellscript [closed]

Deadly 提交于 2021-02-04 21:59:08
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question The Problem: I need to replace a placeholder ( __PLACEHOLDER__ ) in a html file index.html with 1-n specific values defined in a config.json file. what I tried: replacing the placeholder inside index.html with new content: echo "${html//__PLACEHOLDER__/$replace}" > index.html

replacing a placeholder in a html file with 1-n specific values defined in a config.json using shellscript [closed]

浪子不回头ぞ 提交于 2021-02-04 21:58:23
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question The Problem: I need to replace a placeholder ( __PLACEHOLDER__ ) in a html file index.html with 1-n specific values defined in a config.json file. what I tried: replacing the placeholder inside index.html with new content: echo "${html//__PLACEHOLDER__/$replace}" > index.html

Apply Perl RegExp to Remove Parenthesis and Text at End of String

只谈情不闲聊 提交于 2021-02-04 21:38:32
问题 I have a string which includes parenthesis with text inside the parenthesis. How do I remove the parenthesis with text at the end of the string while keeping the other words in string? Input: Potatoes Rice (Meat) Output: Potatoes Rice My code: #! /usr/bin/perl use v5.10.0; use warnings; my $noparenthesis = "Potatoes Rice (Meat)"; $noparenthesis =~ s/^/$1/gi; say $noparenthesis; 回答1: #! /usr/bin/perl use v5.10.0; use warnings; my $noparenthesis = "Potatoes Rice (Meat)"; $noparenthesis =~ s/\(.

Calling a shell command with multiple arguments

给你一囗甜甜゛ 提交于 2021-02-04 21:07:34
问题 I'm trying to automate creating certificates via a Perl script. The command I want to run is: easyrsa build-client-full $clientname nopass The way I thought it should be done in Perl is: my $arguments = ("build-client-full $clientname nopass"); my $cmd = "$easyrsa_path/easyrsa"." "."$arguments"; system("bash", $cmd); However, this yields "file not found" on execution. I triple checked that the path is correct. If I try it like this: my @arguments = ("bash", $easyrsa_path,"build-client-full