просто напечатайте i вместо j
for(int i=1; i<=10; i++){
int factors = 0;
int j=1;
while(j<=i){
if(i % j == 0){
factors++;
}
j++;
}
if(factors==2){
System.out.println(i);
}
}
Это не ответ, это скорее подсказка, чтобы помочь вам начать. Он не использует Regex
Dim Parts() as string
FullText = "12/07/2018 AB CART 9000341 FAXED TO INSTITUTION 12/10/2018 JT follow up with institution, currently processing, follow up on 12/13 12/13/2018 JR LIB missing, faxed to INSTITUTION, follow up on 12/19 12/18/2018 AB Documents recieved, currently in processing, follow up on 12/22 12/27/2018 LP LIB rejected - Fax illegible, faxed to Institution, follow up on 12/27"
Parts = split(ucase(FullText),"FAXED")
' Now you have 2 parts Parts(0) = Text before word Faxed, Parts(1) = Text after word Faxed
' Following will give you position of rightmost / character in Part(0) - part of the date you want
Pos1 = InStrRev(Part(0),"/")
Надеюсь, это поможет
Даты в вашей строке представлены в формате mm/dd/yyyy
, поэтому регулярное выражение записывается соответствующим образом.
Значение возвращается как дата, но вы можете отформатировать ячейку по своему усмотрению.
Option Explicit
Function lastFaxedDt(s As String) As Date
Dim RE As RegExp, MC As MatchCollection
Const sPat As String = "(\b(?:0[1-9]|1[0-2])/(?:0[1-9]|[12]\d|3[01])/(?:19\d{2}|[2-9]\d{3})\b)(?=.*?faxed)"
Set RE = New RegExp
With RE
.Pattern = sPat
.IgnoreCase = True
.Global = True
If .Test(s) = True Then
Set MC = .Execute(s)
lastFaxedDt = CDate(MC(MC.Count - 1))
End If
End With
End Function
Снимок экрана, на котором показаны совпадающие даты: