regex

Replacing filename with a Regex in JavaScript

ぐ巨炮叔叔 提交于 2021-02-11 13:23:57
问题 I need to replace a button using a Regex in JavaScript and was wondering how to do this. I know how to grab the src of the button, but I need to take the filename and either add some text "-next" or remove "-next", based on two options that can be toggled. Here are the two different file names: /images/button.png /images/button-next.png Any help would be greatly appreciated. 回答1: To insert a -next before the final dot, you could do result = subject.replace(/(?=\.[^.]+$)/g, "-next"); To remove

django-ORM的查询条件

余生颓废 提交于 2021-02-11 13:05:21
前提是创建好了ORM的模型(参照https://www.cnblogs.com/ifdashui/p/11901084.html) 现在数据库中存在下列的数据(以下的查询条件根据这些数据做处理) 在models.py中 # -*- coding: UTF-8 -*- from django.db import models class Article(models.Model): title = models.CharField(max_length=200 ) content = models.TextField() class Meta: db_table = ' article ' # 更改这个表的名字,映射到数据中的话名称不是Article_article了,是你自定义设置的article 使用下面这两条命令在数据库中映射:(注意进入项目路径以及有虚拟环境的进入虚拟环境) python manage.py makemigrations python manage.py migrate 接下来就在views.py中操作即可 在model.py中,创建一个ORM模型 from django.db import models class Article(models.Model): title = models.CharField(max_length=200 ) content

Python regex search giving none when it should match

China☆狼群 提交于 2021-02-11 12:46:53
问题 So I have... regex = re.compile('\d{4,}:\s##(.*)##') regex_search = regex.search(line.mesg) # This code is abbreviated. I go on to do things with # "result" in the try block but rather than junk up this # post, here's the gist: try: result = regex_search.group(1) except AttributeError: print regex_search Sample 'line.mesg' input (4 separate instances of line.mesg): ##Loading task.## ##BEEP (375,2)## ##Aisle One One Seven##;pp ##Good night.## Now, according to the testing at pythex.org (click

Python regex search giving none when it should match

老子叫甜甜 提交于 2021-02-11 12:45:08
问题 So I have... regex = re.compile('\d{4,}:\s##(.*)##') regex_search = regex.search(line.mesg) # This code is abbreviated. I go on to do things with # "result" in the try block but rather than junk up this # post, here's the gist: try: result = regex_search.group(1) except AttributeError: print regex_search Sample 'line.mesg' input (4 separate instances of line.mesg): ##Loading task.## ##BEEP (375,2)## ##Aisle One One Seven##;pp ##Good night.## Now, according to the testing at pythex.org (click

Problem with brackets in regular expression in C#

本秂侑毒 提交于 2021-02-11 12:44:46
问题 can anybody help me with regular expression in C#? I want to create a pattern for this input: {a? ab 12 ?? cd} This is my pattern: ([A-Fa-f0-9?]{2})+ The problem are the curly brackets. This doesn't work: {(([A-Fa-f0-9?]{2})+)} It just works for {ab} 回答1: I would use {([A-Fa-f0-9?]+|[^}]+)} It captures 1 group which: Match a single character present in the list below [A-Fa-f0-9?]+ Match a single character not present in the list below [^}]+ 回答2: If you allow leading/trailing whitespace within

Extract string between brackets

此生再无相见时 提交于 2021-02-11 12:40:25
问题 I would like to extract characters between first opening and last closing brackets in a string like match[input[name="firstname"]] considering the characters to retrieve may also contain more brackets. In this case it would get input[name="firstname"] Also, the string may contain some special characters like { # / \ ^ 回答1: This somehow awkward-looking regular expression /[^[\]]+\[[^[\]]+\]/ basically says "no brackets, then [, then no brackets, then ]". s = 'match[input[name="firstname"]]' >

See apple-app-site-association file in .well-known directory despite RewriteCond

早过忘川 提交于 2021-02-11 12:33:55
问题 In my sites hosted on Dreamhost, the .well-known directory contains an acme-challenge folder along with an .htaccess like this: # Permit access to the challenge files but nothing else Order allow,deny Allow from all RewriteCond %{REQUEST_URI} ^/[.]well-known/acme-challenge/[a-zA-Z0-9_-]+$ RewriteRule .* - [L] RewriteRule .* - [F] Therefore when I put my apple-app-site-association file into .well-known , it isn't seen. How would I modify the .htaccess to permit this? Would I just stick in

Regex for TODO keyword when passing through a list of directories to get a list of files with TODO keyword (eg. //TODO) but not as variable / string

自作多情 提交于 2021-02-11 12:24:21
问题 I'm trying to write an application that looks through a directory and flag out all files (be it in directory or subdirectories) that has the TODO keyword (the one that flashes/highlights in color whenever we code in our code editor [i am using visual studio code] I have gotten most of the code running, its just the last bit that is puzzling me : because my RegEx accepts 'TODO' as a word block, it picks up even files that has TODO as variable name / string content eg. var todo = 'TODO' or var

Grep for lines not beginning with “//”

a 夏天 提交于 2021-02-11 12:11:54
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world

Grep for lines not beginning with “//”

こ雲淡風輕ζ 提交于 2021-02-11 12:04:38
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world