我在文件中有一些文字:
<form [formGroup]="myFormGroup" *ngIf="myFormGroup" (ngSubmit)="onSubmit()">
<div>
<label for="name">Name:</label>
<input type="text" name="name" id="name" formControlName="name" />
</div>
<div>
<label for="myCheckbox">My Checkbox:</label>
<input type="checkbox" name="myCheckbox" id="myCheckbox" formControlName="myCheckbox" />
</div>
<div>
<button type="submit" [disabled]="!myFormGroup.valid">Submit!</button>
</div>
<div *ngIf="myFormGroup.errors">
{{myFormGroup.errors | json}}
</div>
</form>
我只想找到这部分:
import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';
@Pipe({
name: 'dateFormat'
})
export class DateFormatPipe extends DatePipe implements PipeTransform {
transform(value: any, args?: any): any {
switch (args) {
case 'en': {
return super.transform(value, 'MM/dd/yyyy h:mm a');
}
case 'fr': {
return super.transform(value, 'dd/MM/yyyy HH:mm'); // <--- find proper separator
}
case 'de': {
return super.transform(value, 'dd.MM.yyyy HH:mm');
}
case 'es': {
return super.transform(value, 'yyyy/MM/dd hh:MM');
}
}
}
}
我知道我可以使用此正则表达式:
class GroupsWizard(SessionWizardView):
def get_template_names(self):
return 'index.html'
def get_context_data(self, form, **kwargs):
context = super(GroupsWizard, self).get_context_data(form = form, **kwargs)
context_data = Groups.objects.all()
context.update({'context_data': context_data})
return context
def done(self, form_list, **kwargs):
data = {k: v for form in form_list for k, v in form.cleaned_data.items()}
instance = Groups.objects.create(**data)
return render(self.request, 'done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
我想做的是用逗号25968.254.000.1234.784.000000000000.85 8547968.82 0 874968.21 5896314.42
替换第一部分中的句号25968.254.000.1234.784.000000000000.85 8547968.82
,最后得到以下内容:
^\d{5}\.(\d{3})\.\d{3}\.(\d{4})\.\d{3}\.(\d{12})\.\d{2}\s([0-9.]*)\s
我该怎么做?
谢谢
答案 0 :(得分:0)
您需要使用正则表达式capture-groups。
您将每个数字组包装在()中,然后使用\ N引用它们,其中N是第N个组。
将此用于查找:
create table subject as
select 1 id, 'Humanities' name from dual union all
select 2 , 'Science' from dual union all
select 3 , 'Math' from dual
;
create table course_semester as
select 1 id_subject, 201801 semester, 1002 as id_profesor from dual union all
select 2 , 201702 , 1002 as id_profesor from dual union all
select 3 , 201801 , 1002 as id_profesor from dual
;
CREATE OR REPLACE FUNCTION listar_cursos(prof NUMBER) RETURN VARCHAR IS
test VARCHAR(500);
BEGIN
FOR item IN
(
SELECT subject.name AS name FROM subject
INNER JOIN course_semester
ON subject.id = course_semester.id_subject
WHERE course_semester.id_profesor = prof
ORDER BY subject.name
)
LOOP
test:= test || ',' || item.name;
END LOOP;
RETURN ltrim(test, ',');
END;
/
select listar_cursos(1002) from dual;
LISTAR_CURSOS(1002)
-----------------------
Humanities,Math,Science
然后将其替换:
^(\d{5}).(\d{3}).(\d{3}).(\d{4}).(\d{3}).(\d{12}).(\d{2})\s([0-9.]*)\s
答案 1 :(得分:0)
如果仅在某些数字之后,则将其替换为逗号,从行的开头一直到找到一个非数字字符为止。它适用于任意数量的数字点。
(?:^|\G)(\d+)\.
$1,
说明:
(?: : start non capture group
^ : beginning of line
| : OR
\G : restart from last match
) : end group
(\d+) : group 1, 1 or more digits
\. : a dot
替换:
$1 : content of group 1 (i.e. the digits)
, : a comma
给定示例的结果
25968,254,000,1234,784,000000000000,85 8547968.82 0 874968.21 5896314.42